<template>
  <pageTabelLayout>
    <template #pageTabel>
      <a-tabs   :lazy-load="true" :justify="true" :default-active-key="tbsData.tableIndex" @change="changetabs">
        <a-tab-pane key="1" title="需求计划单待处理">
          <pageTabelLayout>
            <template #pageHeader>
              <div class="xqdxx">
                <a-form size="mini" :model="pageData" layout="inline"
                        v-if="permissionStore.hasPermisson('cjsgd.xqddclcx1')">
                  <a-form-item :style="{ width: '275px' }" label-col-flex="80px" label="需求公司">
                    <a-cascader v-model="isDatas.is" :options="pageData.nameListq1" allow-clear ref="casOb5"
                                @change="cascaderChange5($event, isDatas.is)" class="bacClass" :title="pageData.title5"
                                :loading="pageData.loading5" popup-container="html"/>
                  </a-form-item>
                  <a-form-item :style="{ width: '275px' }" label-col-flex="80px" label="需求部门">
                    <a-cascader v-model="isDatas.is1" :options="pageData.nameListq" allow-clear ref="casOb6"
                                :disabled="isDatas.is == null || isDatas.is == ''" @change="cascaderChange6"
                                class="bacClass"
                                :title="pageData.title6" :loading="pageData.loading6"
                                style="border: 1px solid #a29f9f !important;" popup-container="html"/>
                  </a-form-item>
                  <a-form-item :style="{ width: '275px' }" label-col-flex="80px" label="需求单号">
                    <!-- <a-select popup-container="html"  class="bacClass" :style="{ width: '200px' }" :loading="loading"
                                                                                                                                                @search="handleSearch" v-model="pageData.dropDownData" :filter-option="false"
                                                                                                                                                allow-search allow-clear @focus="focusSel">
                                                                                                                                                <a-option v-for="item in pageData.nameList" :value="item">{{
                                                                                                                                                    item
                                                                                                                                                }}</a-option>
                                                                                                                                            </a-select> -->
                    <a-input class="bacClass" placeholder="" v-model="pageData.dropDownData123" @press-enter="huiche"
                             allow-clear/>
                  </a-form-item>
                  <a-form-item :style="{ width: '275px' }" label-col-flex="80px" label="需求人">
                    <!-- <a-select popup-container="html"  class="bacClass" :style="{ width: '200px' }" :loading="loading"
                                                                                                                                                @search="xuQiur" v-model="isDatas.is2" :filter-option="false" allow-search
                                                                                                                                                allow-clear @focus="xuQiurs">
                                                                                                                                                <a-option v-for="item in isDatas.is2Array" :value="item">{{
                                                                                                                                                    item
                                                                                                                                                }}</a-option>
                                                                                                                                            </a-select> -->
                    <a-input class="bacClass" placeholder="" v-model="isDatas.is2" @press-enter="huiche" allow-clear/>
                  </a-form-item>
                  <a-form-item :style="{ width: '275px' }" label-col-flex="80px" label="需求类型">
                    <!-- <a-select popup-container="html"  class="bacClass" :style="{ width: '200px' }" :loading="loading" @search="xuQiuLeix"
                          v-model="isDatas.is3" :filter-option="false" allow-search allow-clear @focus="xuQiuLeixs">
                          <a-option v-for="item in isDatas.is3Array" :value="item">{{
                            item
                          }}</a-option>
                        </a-select> -->
                    <a-select popup-container="html" class="bacClass" v-model="isDatas.is3" allow-clear
                              @change="typeChange">
                      <a-option style="color: red; font-weight: bolder" value="0" @press-enter="huiche">加急</a-option>
                      <a-option style="color: green; font-weight: bolder" value="1" @press-enter="huiche">计划
                      </a-option>
                      <a-option style="color: blue; font-weight: bolder" value="2" @press-enter="huiche">临时</a-option>
                    </a-select>
                    <!-- <a-input class="bacClass" placeholder="" v-model="isDatas.is3" @press-enter="huiche" allow-clear /> -->
                  </a-form-item>
                  <a-form-item :style="{ width: '275px' }" label-col-flex="80px" label="仓库名称">
                    <!-- <a-select popup-container="html"   class="bacClass" :style="{ width: '200px' }" :loading="loading"
                                                                                                                                                @search="xuQiuCk" v-model="isDatas.is4" :filter-option="false" allow-search
                                                                                                                                                allow-clear @focus="xuQiuCks">
                                                                                                                                                <a-option v-for="item in isDatas.is4Array" :value="item">{{
                                                                                                                                                    item
                                                                                                                                                }}</a-option>
                                                                                                                                            </a-select> -->
                    <a-input class="bacClass" placeholder="" v-model="isDatas.is4" @press-enter="huiche" allow-clear/>
                  </a-form-item>
                  <a-form-item :style="{ width: '275px' }" label-col-flex="80px" label="物料名称">
                    <!-- <a-select popup-container="html"  class="bacClass" :style="{ width: '200px' }" :loading="loading"
                                                                                                                                                @search="xuQiuWl" v-model="isDatas.is5" :filter-option="false" allow-search
                                                                                                                                                allow-clear @focus="xuQiuWls">
                                                                                                                                                <a-option v-for="item in isDatas.is5Array" :value="item">{{
                                                                                                                                                    item
                                                                                                                                                }}</a-option>
                                                                                                                                            </a-select> -->
                    <a-input class="bacClass" placeholder="" v-model="isDatas.is5" @press-enter="huiche" allow-clear/>
                  </a-form-item>
                  <a-form-item :style="{ width: '275px' }" label-col-flex="80px">
                    <template #label> 规&nbsp;&nbsp;&nbsp;格</template>
                    <!-- <a-select popup-container="html"  class="bacClass" :style="{ width: '200px' }" :loading="loading"
                                                                                                                                                @search="xuQiuGg" v-model="isDatas.is6" :filter-option="false" allow-search
                                                                                                                                                allow-clear @focus="xuQiuGgs">
                                                                                                                                                <a-option v-for="item in isDatas.is6Array" :value="item">{{
                                                                                                                                                    item
                                                                                                                                                }}</a-option>
                                                                                                                                            </a-select> -->
                    <a-input class="bacClass" placeholder="" v-model="isDatas.is6" @press-enter="huiche" allow-clear/>
                  </a-form-item>
                  <a-form-item :style="{ width: '480px' }" label-col-flex="80px" label="开单日期">
                    <el-date-picker class="bacClass" type="date" v-model="pageData.dropDownDataqszs.startDate"
                                    placeholder="开始日期" size="small"/>
                    <span>至</span>
                    <el-date-picker class="bacClass" type="date" v-model="pageData.dropDownDataqszs.endDate"
                                    placeholder="结束日期" size="small"/>
                  </a-form-item>
                  <a-form-item :style="{ width: '270px' }" label-col-flex="80px"></a-form-item>
                </a-form>
                <a-space>
                  <Toolbar :items="[
                `${permissionStore.hasPermisson('cjsgd.xqdxqdcjsgd1') ? '查询' : ''}`,
                `${permissionStore.hasPermisson('cjsgd.xqddclcx1') ? '需求单创建申购单' : ''}`,
                `${permissionStore.hasPermisson('cjsgd.xqddclcjsgd1') ? '创建申购单' : ''}`,
              ]" @select="selectSh" @xuCreatego="handleBeforeOk" @Creatego="handleBeforeOks"></Toolbar>
                </a-space>
              </div>
            </template>
            <template #pageTabel>
              <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
                <AgGridVuesCopys :rowHeight="33" :headerHeight="33" rowSelection="multiple" @grid-ready="gridReady"
                                 style="height:calc(100% - 45px)"
                                 :defaultColDef="defaultColDef" class="ag-theme-alpine" :rowData="table.dataList"
                                 :columnDefs="tc"
                                 :localeText="localeText1" rowKey="id" :suppressCopyRowsToClipboard="true">
                </AgGridVuesCopys>
              </a-spin>
            </template>
          </pageTabelLayout>
        </a-tab-pane>
        <a-tab-pane key="2" title="申购单">
          <pageTabelLayout>
            <template #pageHeader>
              <div class="xqdxx">
                <a-form size="mini" :model="pageData" layout="inline"
                        v-if="permissionStore.hasPermisson('cjsgd.sgdcx1')">
                  <a-form-item label="申购单号">
                    <!-- <a-select popup-container="html"  class="bacClass" :loading="loading1" @search="handleSearch1"
                                                                                                                                            v-model="pageData.dropDownData1" :filter-option="false" allow-search allow-clear
                                                                                                                                            @focus="focusSel1">
                                                                                                                                            <a-option v-for="item in pageData.nameList" :value="item['applyCode']">{{
                                                                                                                                                item['applyCode']
                                                                                                                                            }}</a-option>
                                                                                                                                        </a-select> -->
                    <a-input class="bacClass" placeholder="" v-model="pageData.dropDownData1" @press-enter="huiche2"
                             allow-clear/>
                  </a-form-item>
                </a-form>
                <div style="text-align: right; width: 100%">
                  <!-- <a-button type="outline" @click="tjWl">添加申购信息</a-button> -->
                  <Toolbar :items="[`${permissionStore.hasPermisson('cjsgd.sgdcx1') ? '查询' : ''}`]"
                           @select="selectInfo">
                  </Toolbar>
                  <!-- <a-button type="primary" size="mini" @click="cxAllInfo" style="margin-right: 10px; position: relative">查询
                  </a-button> -->
                  <!-- <a-button type="primary" size="mini" @click="tjWl" style="margin-right: 10px;">提交
                                                                                                                                      </a-button> -->
                  <!-- <a-button type="primary" @click="delQk" size="mini" style="margin-right: 10px;">清空</a-button>
                                                                                                                                      <a-button type="primary" @click="addXqiu" size="mini" style="margin-right: 10px;">确认</a-button> -->
                </div>
              </div>
            </template>
            <template #pageTabel>
              <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
                <AgGridVuesCopys :rowHeight="33" :headerHeight="33" rowSelection="multiple" @grid-ready="gridReadys"
                                 style="height:calc(100% - 45px)"
                                 :defaultColDef="defaultColDefs" class="ag-theme-alpine" :rowData="isDataLists"
                                 :columnDefs="tcs"
                                 :localeText="localeText1" :suppressCopyRowsToClipboard="true"></AgGridVuesCopys>
                <paginationCopys :page-size-options="pagingList1" v-if="pageData.isKey == 2" :total="pagination.total"
                                 show-total show-jumper show-page-size @change="PageSize" @page-size-change="change1"
                                 style="justify-content: center"
                                 :page-size="pagination.pageSize" :current="pagination.page"/>
              </a-spin>
            </template>
          </pageTabelLayout>
        </a-tab-pane>
        <a-tab-pane key="3" title="需求计划单已处理">
          <div class="xqdxx">
            <a-form size="mini" :model="pageData" layout="inline"
                    v-if="permissionStore.hasPermisson('cjsgd.xqdyclcx1')">
              <a-form-item label="需求单号">
                <a-input class="bacClass" placeholder="" v-model="pageData.dropDownData" @press-enter="huiche3"
                         allow-clear/>
              </a-form-item>
            </a-form>

            <div style="text-align: right; width: 100%">
              <Toolbar :items="[`${permissionStore.hasPermisson('cjsgd.xqdyclcx1') ? '查询' : ''}`]" @select="cxAllYtj">
              </Toolbar>
            </div>
          </div>
          <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
            <AgGridVuesCopys :rowHeight="33" :headerHeight="33" rowSelection="multiple" @grid-ready="gridReadysz"
                             style="height: 85%"
                             :suppressCopyRowsToClipboard="true" :defaultColDef="defaultColDefsz"
                             class="ag-theme-alpine"
                             :rowData="pageData.xqDataList" :columnDefs="tcsz"
                             :localeText="localeText1"></AgGridVuesCopys>
          </a-spin>
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-drawer style="z-index: 999" ok-text="保存" cancel-text="关闭"
              :drawer-style="{ zIndex: 1001, border: '1px solid #ccc' }" popup-container=".arco-tabs-content"
              height="100%"
              placement="bottom" :ok-loading="pageData.pageLoading" :visible="pageData1.showAdd" unmountOnClose
              @close="onClose"
              @ok="sideOks" @cancel="cancelDelet">
      <template #title>
        {{ pageData1.title }}
      </template>

      <div style="width: 1540px; overflow: auto" v-loading="loadingbm">
        <el-scrollbar>
          <a-form size="mini" ref="formRef" layout="inline" :model="dataForm" :label-col-props="{ span: 11 }"
                  :wrapper-col-props="{ span: 13 }">
            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购人">
              <a-input :style="{ width: '22rem' }" disabled placeholder="" v-model="dataForm.applyPerson"
                       class="bacClass"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购单号">
              <a-input disabled :style="{ width: '22rem' }" v-model="dataForm.applyCode" class="bacClass"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购公司"
                         :rules="[{ required: true, message: '公司必填' }]" :validate-trigger="['change', 'blur']">
              <a-cascader v-model="dataForm.applyCompany" :options="pageData.firmGroupList" allow-clear ref="casOb"
                          @change="cascaderChange($event, dataForm.applyCompany)" class="bacClass"
                          :title="pageData.title"
                          :loading="pageData.loading" popup-container="html"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购部门" field="applyDepartmentId"
                         :rules="[{ required: true, message: '部门必填' }]" :validate-trigger="['change', 'blur']">
              <a-cascader v-model="dataForm.applyDepartmentId" :options="pageData.bmList" allow-clear ref="casOb1"
                          class="bacClass" :disabled="dataForm.applyCompany == null || dataForm.applyCompany == ''"
                          @change="cascaderChange1" :class="bacClass" :title="pageData.title1"
                          :loading="pageData.loading1" popup-container="html"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="采购公司" field="useCompany"
                         :rules="[{ required: true, message: '公司必填' }]" :validate-trigger="['change', 'blur']">
              <a-cascader disabled v-model="dataForm.useCompany" :options="pageData.firmGroupList1" allow-clear
                          ref="casOb2" @change="cascaderChange2($event, dataForm.useCompany)" :title="pageData.title2"
                          :loading="pageData.loading2" class="bacClass" popup-container="html"/>
            </a-form-item>

            <!-- <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="采购部门" field="useDepartmentId"
              :rules="[{ required: true, message: '采购部门必填' }]" :validate-trigger="['change', 'blur']">
              <a-cascader v-model="dataForm.useDepartmentId" :options="pageData.bmList1" allow-clear ref="casOb3"
                :disabled="dataForm.useCompany == null || dataForm.useCompany == ''" @change="cascaderChange3"
                :class="{ bacClass: !(dataForm.useCompany == null || dataForm.useCompany == '') }"
                :title="pageData.title3"   :loading="pageData.loading3" />
            </a-form-item> -->

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购类型" field="applyType"
                         :rules="[{ required: true, message: '申购类型必填' }]" :validate-trigger="['change', 'blur']">
              <a-select popup-container="html" class="bacClass" v-model="dataForm.applyType"
                        :style="{ width: '22rem' }">
                <a-option style="color: red; font-weight: bolder" value="0">加急</a-option>
                <a-option style="color: green; font-weight: bolder" value="1">计划</a-option>
                <a-option style="color: blue; font-weight: bolder" value="2">临时</a-option>
              </a-select>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="计划交货日期"
                         field="planDeliveryDate"
                         :rules="[{ required: true, message: '日期必填' }]" :validate-trigger="['change', 'blur']">
              <a-date-picker popup-container="html" class="bacClass" style="width: 22rem"
                             :time-picker-props="{ defaultValue: '00:00:00' }"
                             format="YYYY-MM-DD" v-model="dataForm.planDeliveryDate"/>
            </a-form-item>

            <a-form-item label="备注" field="remark" :style="{ width: '888px' }" label-col-flex="120px">
              <a-textarea class="bacClass" v-model="dataForm.remark" :max-length="400" allow-clear show-word-limit/>
            </a-form-item>
          </a-form>
          <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
            <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :enableCellTextSelection="true" rowSelection="multiple"
                             @grid-ready="gridReadysz111"
                             style="height: 580px;width: 100%;" :defaultColDef="defaultColDefsz111"
                             class="ag-theme-alpine"
                             :rowData="pageData.tqDataList" :columnDefs="tcsz111"></AgGridVuesCopys>
          </a-spin>
        </el-scrollbar>
      </div>
    </a-drawer>
    <a-modal v-model:visible="visible1" title="申购单详情" :width="1200" :footer="false" :draggable="true">
      <a-table :style="{
        height: '100%',
        marginTop: '10px',
      }" stripe :bordered="true" :scrollbar="true" sticky-header :columns="tableColumns3"
               :data="pageData.isDetailsList">
      </a-table>
    </a-modal>
    <!-- </div> -->

    <a-drawer style="z-index: 999" ok-text="保存" cancel-text="关闭"
              :drawer-style="{ zIndex: 1001, border: '1px solid #ccc' }" popup-container=".arco-tabs-content"
              height="100%"
              placement="bottom" :ok-loading="pageData.pageLoading" :visible="isDtasZh" unmountOnClose @ok="sideOkss"
              @cancel="cancelDelets">
      <template #title>
        {{ sgTitels }}
      </template>

      <div style="width: 1540px; overflow: auto" v-loading="loadingbm">
        <el-scrollbar>
          <a-form size="mini" ref="formRefSave" layout="inline" :model="dataForm" :label-col-props="{ span: 11 }"
                  :wrapper-col-props="{ span: 13 }">
            <!-- <a-form-item label="申购人" field="applyPerson" :rules="[{ required: true, message: '申购人必填' }]"
                                                                                                                                      :validate-trigger="['change', 'blur']">
                                                                                                                                      <a-input class="bacClass" :style="{ width: '22rem' }" v-model="dataForm.applyPerson"
                                                                                                                                          :disabled="pageData1.title != '创建申购单'" />
                                                                                                                                  </a-form-item> -->
            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购人">
              <a-input :style="{ width: '22rem' }" disabled placeholder="" v-model="dataForm.applyPerson"
                       class="bacClass"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购单号">
              <a-input disabled :style="{ width: '22rem' }" v-model="dataForm.applyCode" class="bacClass"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购公司"
                         :rules="[{ required: true, message: '公司必填' }]" :validate-trigger="['change', 'blur']">
              <a-cascader v-model="dataForm.applyCompany" :options="pageData.firmGroupList" allow-clear ref="casOb"
                          @change="cascaderChange($event, dataForm.applyCompany)" class="bacClass"
                          :title="pageData.title"
                          :loading="pageData.loading" popup-container="html"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购部门" field="applyDepartmentId"
                         :rules="[{ required: true, message: '部门必填' }]" :validate-trigger="['change', 'blur']">
              <a-cascader v-model="dataForm.applyDepartmentId" :options="pageData.bmList" allow-clear ref="casOb1"
                          :disabled="dataForm.applyCompany == null || dataForm.applyCompany == ''"
                          @change="cascaderChange1"
                          class="bacClass" :title="pageData.title1" :loading="pageData.loading1"
                          popup-container="html"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="采购公司" field="useCompany"
                         :rules="[{ required: true, message: '公司必填' }]" :validate-trigger="['change', 'blur']">
              <a-cascader v-model="dataForm.useCompany" :options="pageData.firmGroupList1" allow-clear ref="casOb2"
                          @change="cascaderChanges2($event, dataForm.useCompany)" class="bacClass"
                          :title="pageData.title2"
                          :loading="pageData.loading2" popup-container="html"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="采购部门" field=""
                         :rules="[{ required: true, message: '采购部门必填' }]" :validate-trigger="['change', 'blur']">
              <a-cascader v-model="dataForm.useDepartmentId" :options="pageData.bmList1" allow-clear ref="casOb3"
                          :disabled="dataForm.useCompany == null || dataForm.useCompany == ''" @change="cascaderChange3"
                          class="bacClass" :title="pageData.title3" :loading="pageData.loading3"
                          popup-container="html"/>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="申购类型" field="applyType"
                         :rules="[{ required: true, message: '申购类型必填' }]" :validate-trigger="['change', 'blur']">
              <a-select popup-container="html" class="bacClass" v-model="dataForm.applyType"
                        :style="{ width: '22rem' }">
                <a-option style="color: red; font-weight: bolder" value="0">加急</a-option>
                <a-option style="color: green; font-weight: bolder" value="1">计划</a-option>
                <a-option style="color: blue; font-weight: bolder" value="2">临时</a-option>
              </a-select>
            </a-form-item>

            <a-form-item :style="{ width: '280px' }" label-col-flex="120px" label="计划交货日期"
                         field="planDeliveryDate"
                         :rules="[{ required: true, message: '日期必填' }]" :validate-trigger="['change', 'blur']">
              <a-date-picker popup-container="html" class="bacClass" style="width: 22rem"
                             :time-picker-props="{ defaultValue: '00:00:00' }"
                             format="YYYY-MM-DD" v-model="dataForm.planDeliveryDate"/>
            </a-form-item>

            <a-form-item :style="{ width: '888px' }" label-col-flex="120px" label="备注" field="remark">
              <a-textarea class="bacClass" v-model="dataForm.remark" :max-length="400" allow-clear show-word-limit/>
            </a-form-item>
          </a-form>
          <a-space>
            <Toolbar :items="['添加物料', '删除']" @tjWl="tjWl" @del="scWls"></Toolbar>
            <!-- <a-button type="primary" @click="tjWl" size="mini">添加物料</a-button>
            <a-button type="primary" @click="scWls" size="mini">删除</a-button> -->
          </a-space>
          <a-table v-loading="loadingbm" v-if="sgTitels == '新增申购单'" :style="{
            marginTop: '10px',
          }" stripe :bordered="true" :scrollbar="true" sticky-header :columns="tableColumns3" :data="isDataListss"
                   v-model:selected-keys="selectedRowKeys1" row-key="isTypeIds"
                   :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }" size="mini"
                   :pagination="false">
            <template #materialCode="{ record }">
              <a-select popup-container="html" disabled @search="hqWlCodes" v-model="record.materialCode" allow-search
                        allow-clear
                        @click="hqWlCode" @change="hqWlCodezs(record)">
                <a-option v-for="item in isWlCodeList" :value="item.materialCode">{{
                    item.materialCode
                  }}
                </a-option>
              </a-select>
            </template>
            <template #materialName="{ record }">
              <a-select popup-container="html" disabled :loading="loading" @search="handleSearchsm"
                        v-model="record.materialName"
                        :filter-option="false" allow-search allow-clear @focus="focusSelsm" @change="handles(record)">
                <a-option v-for="item in optionssm" :value="item.materialName">{{
                    item.materialName
                  }}
                </a-option>
              </a-select>
            </template>
            <template #specName="{ record }">
              <a-input v-model="record.specName" disabled/>
            </template>
            <template #unit="{ record }">
              <a-input v-model="record.unit" disabled/>
            </template>
            <!-- <template #needNum="{ record }">
              <div style="width: 100%">
                {{ record.needNum }}
              </div>
            </template> -->
            <template #applyNum="{ record }">
              <div style="width: 100%">
                <a-input-number v-model="record.applyNum" class="input-demo bacClass" :min="0" :max="100000000000000"/>
              </div>
            </template>
            <template #stockNum="{ record }">
              <div style="width: 100%">
                <a-input-number disabled v-model="record.stockNum" class="input-demo" :min="0" :max="100000000000000"/>
              </div>
            </template>
            <template #remark="{ record }">
              <a-input class="bacClass" v-model="record.remark"/>
            </template>
          </a-table>
          <a-table v-loading="loadingbm" v-if="sgTitels == '修改申购单'" :style="{
            marginTop: '10px',
          }" stripe :bordered="true" :scrollbar="true" sticky-header :columns="tableColumns3" :data="isDataListss"
                   v-model:selected-keys="selectedRowKeys1" row-key="isTypeIds"
                   :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }" size="mini"
                   :pagination="false">
            <template #materialCode="{ record }">
              <a-select popup-container="html" disabled @search="hqWlCodes" v-model="record.materialCode" allow-search
                        allow-clear
                        @click="hqWlCode" @change="hqWlCodezs(record)">
                <a-option v-for="item in isWlCodeList" :value="item.materialCode">{{
                    item.materialCode
                  }}
                </a-option>
              </a-select>
            </template>
            <template #materialName="{ record }">
              <a-select popup-container="html" disabled :loading="loading" @search="handleSearchsm"
                        v-model="record.materialName"
                        :filter-option="false" allow-search allow-clear @focus="focusSelsm" @change="handles(record)">
                <a-option v-for="item in optionssm" :value="item.materialName">{{
                    item.materialName
                  }}
                </a-option>
              </a-select>
            </template>
            <template #specName="{ record }">
              <a-input v-model="record.specName" disabled/>
            </template>
            <template #unit="{ record }">
              <a-input v-model="record.unit" disabled/>
            </template>
            <!-- <template #needNum="{ record }">
              <div style="width: 100%">
                {{ record.needNum }}
              </div>
            </template> -->
            <template #applyNum="{ record }">
              <div style="width: 100%">
                <a-input-number v-model="record.applyNum" class="input-demo bacClass" :min="0" :max="100000000000000"/>
              </div>
            </template>
            <template #stockNum="{ record }">
              <div style="width: 100%">
                <a-input-number v-model="record.stockNum" class="input-demo" disabled :min="0" :max="100000000000000"/>
              </div>
            </template>
            <template #remark="{ record }">
              <a-input class="bacClass" v-model="record.remark"/>
            </template>
          </a-table>
        </el-scrollbar>
      </div>
    </a-drawer>
    <a-modal v-model:visible="visible6" title="系统提示" :draggable="true">
      <a-form-item label="是否驳回订单?"></a-form-item>
      <a-form-item label="驳回原因：">
        <a-input class="bacClass" allow-clear v-model="dataForm.rejectCause"></a-input>
      </a-form-item>
      <template #footer>
        <el-button @click="visible6 = false && dataForm.rejectCause == ''">取消</el-button>
        <el-button type="primary" @click="okk">确认</el-button>
      </template>
    </a-modal>

    <a-modal fullscreen v-model:visible="visibleWl" :on-before-ok="handleOk" @cancel="handleCancel"
             :mask-closable="false">
      <template #title> 选择物料信息</template>
      <div style="width: 85%; display: flex; justify-content: space-between">
        <div>
          <span>物料大类:</span>
          <a-select popup-container="html" class="bacClass" :loading="WLloading" @search="WLhandleSearch"
                    v-model="bigClassName" @change="bigChange"
                    :filter-option="false" allow-search allow-clear @focus="WLfocusSel" style="width:200px">
            <a-option v-for="item in pageData.bigName">
              {{ item }}
            </a-option>
          </a-select>
        </div>
        <div>
          <span>物料小类:</span>
          <a-select popup-container="html" class="bacClass" :loading="WLloading1" @search="WLhandleSearch1"
                    v-model="subClassName"
                    :filter-option="false" allow-search allow-clear @focus="WLfocusSel1" style="width:200px">
            <a-option v-for="item in pageData.samllName">
              {{ item }}
            </a-option>
          </a-select>
        </div>
        <div>
          <span>物料编号:</span>
          <a-select popup-container="html" class="bacClass" :loading="WLloading2" @search="WLhandleSearch2"
                    v-model="materialCode"
                    :filter-option="false" allow-search allow-clear @focus="WLfocusSel2" @change="WLhandleCode"
                    style="width:200px">
            <a-option v-for="item in pageData.codeList" :value="item.materialCode + '——' + item.materialName">
              {{ item["materialCode"] + ' —— ' + item["materialName"] }}
            </a-option>
          </a-select>
        </div>
        <div>
          <span>物料名称:</span>
          <a-select popup-container="html" class="bacClass" :loading="WLloading3" @search="WLhandleSearch3"
                    v-model="materialName"
                    :filter-option="false" allow-search allow-clear @focus="WLfocusSel3" @change="WLhandleName"
                    style="width:200px">
            <a-option v-for="item in pageData.codeList" :value="item.materialCode + '——' + item.materialName">
              {{ item["materialCode"] + ' —— ' + item["materialName"] }}
            </a-option>
          </a-select>
        </div>
        <div>
          <span>规格:</span>
          <a-select popup-container="html" class="bacClass" :loading="WLloading4" @search="WLhandleSearch4"
                    v-model="specName"
                    :filter-option="false" allow-search allow-clear @focus="WLfocusSel4"
                    style="width:200px">
            <a-option v-for="item in pageData.specList">
              {{ item.specName }}
            </a-option>
          </a-select>
        </div>
        <Toolbar :items="['查询']" @select="Query"></Toolbar>
      </div>
      <a-table :style="{ height: '600px', marginTop: '10px' }"
               :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }" row-key="isTypeIds"
               v-model:selected-keys="selectedRowKeys3" stripe :bordered="true" :scrollbar="true" sticky-header
               :pagination="false" :columns="tableColumns5" :data="dataList">
        <template #picture="{ record }">
          <a-image :src="'/api' + record.picture" style="width:50px;height:50px;"/>
        </template>
      </a-table>
      <paginationCopys :page-size-options="pagingList1" :total="listPage.total" show-total show-jumper show-page-size
                       @change="PageSize3" @page-size-change="change3" style="justify-content: center; margin-top: 50px"
                       :page-size="listPage.size" :current="listPage.page"/>
    </a-modal>
  </pageTabelLayout>
</template>

<script lang="ts">
import {post, get} from '@/api/http'
import {useTable, useRowKey, useTableColumn, usePagination, useRowSelection} from '@/hooks/table'
import emitter from '@/hooks/useEventBus'
import {ref, reactive, onMounted, getCurrentInstance, onUnmounted} from 'vue'
import Toolbar from '@/components/Toolbar.vue'
import {Message} from '@arco-design/web-vue'
import {FormInstance} from '@arco-design/web-vue/es/form'
import XqService from '../orderpurchase/service/xq/index'
import {right} from '@popperjs/core'

import {localeText} from '@/api/aggridZw'
import {pagingList} from '@/api/paging'
import dayjs from 'dayjs'
import {Console} from 'console'
import usePermission from '@/store/modules/permission'
import {slicing} from '@/utils/caseFrimAndSecRig'

interface SettlementType {
  applyCode: any
  applyDate: any
  applyDepartment: any
  applyPerson: any
  planDeliveryDate: any
  useDepartment: any
  supplier: any
  auditDate: any
  deliveryDate: any
  applyType: any
  needDepartment: any
  remark: any
  auditState: any
  auditPerson: any
  deleteState: any
  createName: any
  createTime: any
  updateName: any
  updateTime: any
  id: any
  applyCompany: any
  applyCompanys: any
  useCompany: any
  useCompanys: any
  stockNum: any
  materialName: any
  materialCode: any
  specName: any
  warehouseName: any
  applyNum: any
  applyDepartmentId: any
  useDepartmentId: any
  rejectCause: any
}

export default {
  name: 'ListofRequirements',
  setup() {
    const {proxy} = getCurrentInstance()
    const tabValue = ref<any>(proxy.$route.query.name)
    const tbsData = reactive({
      tableIndex: tabValue.value,
    })

    const paginations11 = {pageSize: 10}
    const XqServices = new XqService()
    const xqOptions = XqServices.xqArrays
    const zjArrays = XqServices.zjArray
    let zjArrays1: any = ref([
      {
        children: [{label: ''}],
      },
    ])
    const casaders = (val: any) => {
      dataForm.needDepartment = ''
      zjArrays1.value = zjArrays.value.filter((res: any) => {
        return val == res.value
      })
    }

    function change1(val: any) {
      pagination.pageSize = val
      cxAllInfo()
    }

    function PageSize(val: any) {
      pagination.page = val
      cxAllInfo()
    }

    const headerShow = ref<boolean>(true)

    function doRefresh() {
      pageData.pageLoading = true
      post({
        url: 'dwPurchase/purchaseNeed/getInfo',
        data: {
          page: pagination.page,
          size: pagination.pageSize,
          needDepartmentId: pageData.dropDownDataq,
          materialName: pageData.dropDownDataqs,
          warehouseName: pageData.dropDownDataqsz,
          ...pageData.dropDownDataqszs,
          specName: pageData.specifications,
          needPerson: pageData.PeopleNeed,
          purchaseNeedCode: pageData.DemandNumber,
        },
      })
          .then(({data, code}: any) => {
            if (code === 200) {
              table.handleSuccess(data)
              pagination.setTotalSize(data.total)
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
    }

    const {selectedRowKeys, onSelectionChange} = useRowSelection()
    const pagination = usePagination(doRefresh)
    const pagination1 = usePagination(doRefreshs)
    const pagination2 = usePagination(doRefresh)
    const table = useTable()
    const rowKey = useRowKey('detailUID')

    const tableColumns1 = useTableColumn([
      // {
      //     title: "需求单号",
      //     key: "needCode",
      //     dataIndex: "needCode",
      //     width: 150
      // },
      {
        title: '申购单号',
        key: 'applyCode',
        dataIndex: 'applyCode',
        width: 150,
      },
      {
        title: '申请日期',
        key: 'applyDate',
        dataIndex: 'applyDate',
        width: 150,
      },
      {
        title: '申购公司',
        key: 'applyCompanys',
        dataIndex: 'applyCompanys',
        width: 150,
      },
      {
        title: '申购部门',
        key: 'applyDepartment',
        dataIndex: 'applyDepartment',
        width: 150,
      },
      {
        title: '申购人',
        key: 'applyPerson',
        dataIndex: 'applyPerson',
        width: 150,
      },
      {
        title: '申购类型',
        key: 'applyType',
        dataIndex: 'applyType',
        slotName: 'applyType',
        width: 150,
      },
      {
        title: '计划交货日期',
        key: 'planDeliveryDate',
        dataIndex: 'planDeliveryDate',
        width: 200,
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        slotName: 'remark',
        width: 150,
      },
      {
        title: '创建人',
        key: 'updateName',
        dataIndex: 'updateName',
        width: 150,
      },
      {
        title: '创建时间',
        key: 'updateTime',
        dataIndex: 'updateTime',
        width: 200,
      },
      {
        title: '操作',
        key: 'action',
        dataIndex: 'action',
        slotName: 'action',
        fixed: right,
        width: 180,
      },
    ])

    const tableColumns2 = useTableColumn([
      {
        title: '物料编号',
        key: 'materialCode',
        dataIndex: 'materialCode',
        slotName: 'materialCode',
        width: 150,
      },
      {
        title: '物料名称',
        key: 'materialName',
        dataIndex: 'materialName',
        slotName: 'materialName',
        width: 150,
      },
      {
        title: '规格',
        key: 'specName',
        dataIndex: 'specName',
        slotName: 'specName',
        width: 150,
      },
      {
        title: '需求数量',
        key: 'needNum',
        dataIndex: 'needNum',
        slotName: 'needNum',
        width: 150,
      },
      {
        title: '申购单数量',
        key: 'applyNum',
        dataIndex: 'applyNum',
        slotName: 'applyNum',
        width: 150,
      },
      {
        title: '单位',
        key: 'unit',
        dataIndex: 'unit',
        slotName: 'unit',
        width: 150,
      },
      {
        title: '库存数量',
        key: 'stockNum',
        dataIndex: 'stockNum',
        slotName: 'stockNum',
        width: 150,
      },
      {
        title: '采购部门',
        key: 'useDepartment',
        dataIndex: 'useDepartment',
        slotName: 'useDepartment',
        width: 150,
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        slotName: 'remark',
        width: 150,
      },
      // {
      //   title: '操作',
      //   key: 'act',
      //   dataIndex: 'act',
      //   slotName: 'act',
      //   fixed: right,
      //   width: 50,
      // },
    ])

    const tableColumns3 = useTableColumn([
      {
        title: '物料编号',
        key: 'materialCode',
        dataIndex: 'materialCode',
        slotName: 'materialCode',
        width: 150,
      },
      {
        title: '物料名称',
        key: 'materialName',
        dataIndex: 'materialName',
        slotName: 'materialName',
        width: 150,
      },
      {
        title: '规格',
        key: 'specName',
        dataIndex: 'specName',
        slotName: 'specName',
        width: 150,
      },
      {
        title: '申购单数量',
        key: 'applyNum',
        dataIndex: 'applyNum',
        slotName: 'applyNum',
        width: 150,
      },
      {
        title: '单位',
        key: 'unit',
        dataIndex: 'unit',
        slotName: 'unit',
        width: 150,
      },
      // {
      //   title: '需求数量',
      //   key: 'needNum',
      //   dataIndex: 'needNum',
      //   slotName: 'needNum',
      //   width: 150,
      // },
      {
        title: '库存数量',
        key: 'stockNum',
        dataIndex: 'stockNum',
        slotName: 'stockNum',
        width: 150,
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        slotName: 'remark',
        width: 150,
      },
    ])
    const pageData = reactive<{
      isDetailsLists: any[]
      nameList: []
      nameLists: []
      nameListz: []
      nameListq: []
      nameListqs: []
      specifications: any
      DemandNumber: any
      PeopleNeed: any
      showAdd: boolean
      sideTitle: string
      dropDownData: any
      dropDownDataq: any
      dropDownDataqs: any
      dropDownDataqsz: any
      dropDownDataqszs: any
      pageLoading: boolean
      rHeight: any
      xqDataList: any[]
      isKey: any
      isDetailsList: any[]
      isDetailsList1: any[]
      tqDataList: any[]
      dropDownData1: any
      firmList: any[]
      firmListsy: any[]
      bmListsy: any[]
      bmList: any[]
      bmList1: any[]
      title: any
      isShow: boolean
      firmGroupList: []
      loading: boolean
      title1: any
      loading1: boolean
      title2: any
      loading2: boolean
      firmGroupList1: []
      title3: any
      loading3: boolean
      firmGroupList3: []
      title5: any
      title6: any
      loading5: boolean
      loading6: boolean
      dropDownDataq1s: any
      nameListq1: any[]
      dropDownData123: any
      isDetail: boolean
      isEdit: boolean
      bigName: any[]
      samllName: any[]
      codeList: any[]
      wlNameList: any[]
      specList: any[]
    }>({
      specName: [],
      bigName: [],
      samllName: [],
      codeList: [],
      wlNameList: [],
      isDetail: false,
      isEdit: false,
      isDetailsLists: [],
      bmList: [],
      bmList1: [],
      loading2: false,
      title2: '',
      loading3: false,
      title3: '',
      firmGroupList3: [],
      loading1: false,
      title1: '',
      firmGroupList: [],
      firmGroupList1: [],
      title: '',
      isShow: true,
      loading: false,
      nameList: [],
      nameLists: [],
      nameListz: [],
      nameListq: [],
      nameListqs: [],
      specifications: '',
      PeopleNeed: '',
      DemandNumber: '',
      showAdd: false,
      sideTitle: '创建申购单',
      dropDownData: '',
      dropDownDataq: '',
      dropDownDataqs: '',
      dropDownDataqsz: '',
      dropDownDataqszs: {
        startDate: dayjs().subtract(7, 'day').format('YYYY-MM-DD'),
        endDate: dayjs().format('YYYY-MM-DD'),
      },
      pageLoading: false,
      rHeight: '',
      xqDataList: [],
      isKey: '1',
      isDetailsList: [],
      isDetailsList1: [],
      tqDataList: [],
      dropDownData1: '',
      firmList: [],
      firmListsy: [],
      bmListsy: [],
      title5: '',
      title6: '',
      loading5: false,
      loading6: false,
      dropDownDataq1s: '',
      nameListq1: [],
      dropDownData123: '',
    })
    const pageData1 = reactive({
      showAdd: false,
      title: '创建申购单',
    })
    //下拉框得到焦点
    const focusSel = () => {
      selCxAll({purchaseNeedCode: '', processedState: 0, auditState: 1})
    }

    //下拉数据
    const options = ref<any>(pageData.nameList)
    const loading = ref(false)
    const handleSearch = (value: any) => {
      if (value) {
        const ob = {purchaseNeedCode: value, processedState: 0, auditState: 1}
        loading.value = true
        window.setTimeout(() => {
          selCxAll(ob)
          options.value = pageData.nameList
          loading.value = false
        }, 200)
      } else {
        options.value = []
      }
    }

    //下拉框查询
    function selCxAll(val: any) {
      if (pageData.isKey == 3) {
        val.processedState = 1
      }
      post({
        url: 'dwPurchase/purchaseNeed/getValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          // (data as string[]).splice(0, 0, "全部");
          pageData.nameList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    //查询申购单号
    //下拉框查询

    //下拉框得到焦点
    const focusSel1 = () => {
      selCxAll1({applyCode: '', selectType: 1})
    }

    //下拉数据
    const options1 = ref<any>(pageData.nameList)
    const loading1 = ref(false)
    const handleSearch1 = (value: any) => {
      if (value) {
        const ob = {applyCode: value, selectType: 1}
        loading1.value = true

        selCxAll1(ob)
        options1.value = pageData.nameList
        loading1.value = false
      } else {
        options1.value = []
      }
    }

    function selCxAll1(val: any) {
      post({
        url: 'dwPurchase/PurchaseApply/getFieldValueGroup',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          // (data as string[]).splice(0, 0, "全部");
          pageData.nameList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    onMounted(() => {
      cxAllInfo()
      getFirmGroup()
      emitter.on('CreateOrder', () => {
        let key = ref(1)
        pageData.isKey = key
        // 第一个页面需要在刚进入就调用一次  切换tap时也需要调用
        if (pageData.isKey == 1) {
          selectSh()
        } else if (pageData.isKey == 2) {
          cxAllInfo()
        } else if (pageData.isKey == 3) {
          cxAllYtj()
        }
        // selCxAll({});
        // 切换tap到本页面执行的方法
        emitter.on('CreateOrder', () => {
          // selCxAll({});
          if (pageData.isKey == 1) {
            selectSh()
          } else if (pageData.isKey == 2) {
            cxAllInfo()
          } else if (pageData.isKey == 3) {
            cxAllYtj()
          }
        })
      })

      pageData.rHeight = document.getElementsByClassName('arco-tabs-content')[0]?.clientHeight

      //表格的高
      if (pageData.rHeight !== undefined) {
        pageData.rHeight = pageData.rHeight + 32
      }
      window.addEventListener('resize', () => {
        pageData.rHeight = document.getElementsByClassName('arco-tabs-content')[0]?.clientHeight

        //表格的高
        if (pageData.rHeight !== undefined) {
          pageData.rHeight = pageData.rHeight + 32
        }
      })
      // foucusUseFrim(1)
      // foucusUseFrim(3)
    })
    //查询
    const selectHandler = () => {
      pagination.page = 1
      doRefreshs()
    }

    //修改申购单号
    const editHandler = (record: any) => {
      if (record.updateState == 0) {
        pageData1.showAdd = true
        selectedRowKeys.value.push(record['uid'])
        pageData1.title = '修改申购单'
        for (var key in record) {
          dataForm[key] = record[key]
        }
        //拿到此页面的详情
        post({
          url: 'dwPurchase/PurchaseApply/getDetail',
          data: {
            applyCode: record['applyCode'],
            rejectState: 0,
          },
        }).then(({data, code}: any) => {
          if (code === 200) {
            getBmGroup(dataForm.applyCompany)
            getBmGroup1(dataForm.useCompany)
            pageData.tqDataList = data[0]['purchaseApplyDetail']
            // pageData.tqDataList =[0]['purchaseApplydata']
            gridOptionsz111.value.setRowData(data[0]['purchaseApplyDetail'])
            isDataListss.value.forEach((item: any) => {
              item['isTypeIds'] = isTypeIds++
            })
            ckNum4()
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      } else {
        isDtasZh.value = true
        for (var key in record) {
          dataForm[key] = record[key]
        }
        sgTitels.value = '修改申购单'
        post({
          url: 'dwPurchase/PurchaseApply/getDetail',
          data: {
            applyCode: record['applyCode'],
            rejectState: 0,
          },
        }).then(({data, code}: any) => {
          if (code === 200) {
            getBmGroup(dataForm.applyCompany)
            getBmGroup1(dataForm.useCompany)
            isDataListss.value = data[0]['purchaseApplyDetail']
            isDataListss.value.forEach((item: any) => {
              item['isTypeIds'] = isTypeIds++
            })
            ckNum2()
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }
    }

    const dataForm = reactive<SettlementType>({
      applyCode: '',
      applyDate: '',
      applyDepartment: '',
      applyPerson: '',
      planDeliveryDate: '',
      useDepartment: '',
      supplier: '',
      auditDate: '',
      deliveryDate: '',
      applyType: '',
      needDepartment: '',
      remark: '',
      auditState: '',
      auditPerson: '',
      deleteState: '',
      createName: '',
      createTime: '',
      updateName: '',
      updateTime: '',
      id: null,
      applyCompany: null,
      applyCompanys: '',
      useCompany: '',
      useCompanys: '',
      stockNum: 0,
      materialName: '',
      materialCode: '',
      specName: '',
      warehouseName: '',
      applyNum: '',
      useDepartmentId: null,
      applyDepartmentId: null,
      rejectCause: '',
    })
    const formRef = ref<FormInstance>()
    const formRefSave = ref<FormInstance>()
    //判断是否填写了中文
    const isChiese = (value: string, cb: Function) => {
      return new Promise<void>((resolve) => {
        if (window.encodeURI(value).indexOf('%') !== -1) {
          cb('填写的值不能包含中文！')
        }
        resolve()
      })
    }
    //input离开焦点 将小写转大写
    const inputBlur = () => {
      // dataForm.settlementCode = dataForm.settlementCode.toUpperCase();
    }

    const isDataList = reactive({
      materialName: '',
      specName: '',
      batchName: '',
      unit: '',
      needNum: '',
      applyNum: '',
      stockNum: 0,
    })

    //下拉框得到焦点
    const focusSels = () => {
      selCxAll({materialName: '', auditState: 1})
    }
    //下拉数据
    const optionss = ref<any>(pageData.nameLists)
    const loadings = ref(false)
    const handleSearchs = (value: any) => {
      if (value) {
        const ob = {materialName: value, auditState: 1}
        loadings.value = true
        window.setTimeout(() => {
          selCxAlls(ob)
          optionss.value = pageData.nameLists
          loadings.value = false
        }, 200)
      } else {
        optionss.value = []
      }
    }

    //下拉框查询
    function selCxAlls(val: any) {
      post({
        url: 'dwPurchase/MaterialInfo/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          // (data as string[]).splice(0, 0, "全部");
          pageData.nameLists = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    let isDataLists: any = ref([])
    const sideOks = () => {
      let isKong = false
      pageData.tqDataList.forEach(function (o: any) {
        if (pageData1.title == '创建申购单') {
          o['id'] = null
        }
        if (o['needNum'] == 0) {
          isKong = false
        }
      })

      // if (
      //   dataForm['applyDepartment'] == '' ||
      //   dataForm['applyType'] == '' ||
      //   dataForm['planDeliveryDate'] == ''
      // ) {
      //   Message.warning({
      //     content: '请将必填字段填写完',
      //     duration: 5000,
      //   })
      //   return
      // }
      // if (isKong) {
      //   Message.warning({
      //     content: '填写的数量必须大于0',
      //     duration: 5000,
      //   })
      //   return
      // }
      // detailUID
      let detailUIDs: any = []
      gridOption.value.getSelectedRows().forEach((item: any) => {
        detailUIDs.push(item.id)
      })

      formRef.value?.validate().then((err: any) => {
        if (!err) {
          let list = []
          for (let i = 0; i < pageData.tqDataList.length; i++) {
            var ob = {}
            ob['materialCode'] = pageData.tqDataList[i].materialCode
            ob['materialName'] = pageData.tqDataList[i].materialName
            ob['specName'] = pageData.tqDataList[i].specName
            ob['needNum'] = pageData.tqDataList[i].needNum
            ob['applyNum'] = pageData.tqDataList[i].applyNum
            ob['unit'] = pageData.tqDataList[i].unit
            ob['stockNum'] = pageData.tqDataList[i].stockNum
            ob['useDepartment'] = pageData.tqDataList[i].useDepartment
            ob['remark'] = pageData.tqDataList[i].remark
            ob['useCompany'] = dataForm.useCompany
            list.push(ob)
          }
          if (pageData1.title == '创建申购单') {
            dataForm['submitState'] = 1
            let useDepartment: string[] = []
            let useDepartmentId = ''
            pageData.tqDataList.map((item: any) => {
              useDepartment.push(...item.useDepartment.split(',', 1))
              useDepartmentId += item.useDepartmentId + "/"
            })
            useDepartment = useDepartment.filter((item: string) => {
              return item && item.trim()
            })
            dataForm.useDepartment = [...new Set(useDepartment)].join(',')
            dataForm.useDepartmentId = [...new Set(useDepartmentId)].join('')
            // pageData.tqDataList.map((item: any) => {
            //   dataForm.useDepartment = item.useDepartment
            //   dataForm.useDepartmentId = item.useDepartmentId
            // })
            pageData.pageLoading = true
            post({
              url: 'dwPurchase/PurchaseApply/insert',
              data: {
                ...dataForm,
                purchaseApplyDetail: list,
                needList: detailUIDs,
                needIds: detailUIDs,
              },
            })
                .then((res: any) => {
                  if (res.code === 200) {
                    post({
                      url: 'dwPurchase/PurchaseApply/upRedis',
                      data: detailUID,
                    })
                    for (let item in dataForm) {
                      dataForm[item] = ''
                    }
                    pageData.dropDownData = ''
                    isDatas.is1 = ''
                    isDatas.is2 = ''
                    isDatas.is3 = ''
                    ;(isDatas.is4 = ''),
                        (isDatas.is5 = ''),
                        (isDatas.is6 = ''),
                        (selectedRowKeys.value = [])
                    formRef.value?.resetFields()
                    doRefreshs()
                    //调查询申购单号的数据
                    // cxAllInfo()
                    Message.success({
                      content: '保存成功!',
                      duration: 5000,
                    })
                    pageData1.showAdd = false
                  } else {
                    Message.error({
                      content: res.message,
                      duration: 5000,
                    })
                  }
                })
                .finally(() => {
                  pageData.pageLoading = false
                })
          } else {
            pageData.pageLoading = true
            pageData.tqDataList.forEach((item: any) => {
              delete item.isTypeIds
            })
            for (let i = 0; i < pageData.tqDataList.length; i++) {
              let o: any = pageData.tqDataList[i]
              if (o['applyNum'] == null) {
                Message.warning({
                  content: '请将申购单数量填写完',
                  duration: 5000,
                })
                pageData.pageLoading = false
                return
              }
            }
            post({
              url: 'dwPurchase/PurchaseApply/update',
              data: {
                ...dataForm,
                purchaseApplyDetail: list,
                // needList: selectedRowKeys.value
              },
            })
                .then((res: any) => {
                  if (res.code === 200) {
                    doRefresh()
                    selectedRowKeys.value = []
                    for (let item in dataForm) {
                      dataForm[item] = ''
                    }
                    //调查询申购单号的数据
                    cxAllInfo()
                    Message.success({
                      content: '保存成功!',
                      duration: 5000,
                    })
                    pageData1.showAdd = false
                  } else {
                    Message.error({
                      content: res.message,
                      duration: 5000,
                    })
                  }
                })
                .finally(() => {
                  pageData.pageLoading = false
                })
          }
          formRef.value?.resetFields()
        }
      })
    }

    const selectInfo = () => {
      pagination.page = 1
      cxAllInfo()
    }
    //查询此人的申购单信息
    const cxAllInfo = () => {
      pageData.pageLoading = true
      //调查询申购单号的数据
      post({
        url: 'dwPurchase/PurchaseApply/selectPageApply',
        data: {
          page: pagination.page,
          size: pagination.pageSize,
          applyCode: pageData.dropDownData1,
          createName: '',
          selectType: 1,
        },
      })
          .then((res: any) => {
            if (res.code === 200) {
              isDataLists.value = res.data.list
              gridOptions.value.setRowData(res.data.list)
              pagination.setTotalSize(res.data.total)
            } else {
              Message.error({
                content: res.message,
                duration: 5000,
              })
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
    }
    //下拉框得到焦点
    const focusSelz = () => {
      selCxAllz({warehouseName: ''})
    }
    //下拉数据
    const optionsz = ref<any>(pageData.nameListz)
    const loadingz = ref(false)
    const handleSearchz = (value: any) => {
      if (value) {
        const ob = {warehouseName: value}
        loadingz.value = true

        selCxAllz(ob)
        optionsz.value = pageData.nameListz
        loadingz.value = false
      } else {
        optionsz.value = []
      }
    }

    //下拉框查询
    function selCxAllz(val: any) {
      post({
        url: 'wms/warehouse/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          // (data as string[]).splice(0, 0, "全部");
          pageData.nameListz = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    let selectedRowKeys1 = ref()
    const cancelsDel = () => {
      if (pageData1.showAdd) {
        return
      } else {
        pageData.showAdd = false
      }
    }
    //查询本人已提交信息
    const cxAllYtj = () => {
      //拿到此页面的详情
      pageData.pageLoading = true
      post({
        url: 'dwPurchase/purchaseNeed/getInfo',
        data: {
          purchaseNeedCode: pageData.dropDownData,
          processedState: 1,
          auditState: 1,
        },
      })
          .then(({data, code}: any) => {
            if (code === 200) {
              pageData.xqDataList = data
              gridOptionsz.value.setRowData(data)
              // pagination2.setTotalSize(data.total);
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
    }

    const scWl = () => {
      if (gridOption.value.getSelectedRows().length == 0) {
        Message.error('请选择要删除的数据')
        return
      }
      let isUid = gridOption.value.getSelectedRows().map((v: any) => {
        return v['uid']
      })
      let filList = pageData.xqDataList.filter(function (o: any) {
        return isUid.includes(o['uid'])
      })
      pageData.xqDataList = pageData.xqDataList.filter(function (o: any) {
        return !isUid.includes(o['uid'])
      })
      var mOb = {}

      filList.forEach(function (o: any) {
        if ((mOb[o['materialName']] = undefined)) {
          mOb[o['materialName']] = 0
        } else {
          mOb[o['materialName']] += o['needNum']
        }
      })
      isDataLists.forEach(function (o: any) {
        mOb[o['materialName']]
      })
      for (let i = 0; i < isDataLists.length; i++) {
        for (var key in isDataLists[i]) {
          for (var key1 in mOb) {
            if (key == key1) {
              isDataLists[i]['needNum'] - mOb[key1]
            }
          }
        }
      }
      // if (selectedRowKeys1.value.length > 1) {

      //     selectedRowKeys1.value.forEach((item: any, index: any) => {

      //         pageData.xqDataList.forEach((items: any, indexs: any) => {
      //             if (item == items.purchaseNeedCode) {
      //                 // selectedRowKeys1.value.splice(index,1)
      //                 pageData.xqDataList.splice(indexs, 1)
      //             }
      //         })
      //     })
      //     if (selectedRowKeys1.value.length > pageData.xqDataList.length) {
      //         selectedRowKeys1.value = []
      //     }
      // } else {
      //     pageData.xqDataList.some((item: any, index: any) => {
      //         if (selectedRowKeys1.value == item.purchaseNeedCode) {
      //             pageData.xqDataList.splice(index, 1)
      //             selectedRowKeys1.value = []
      //         }
      //     })
      // }
      selectedRowKeys1.value = []
    }
    //下拉框得到焦点
    const focusSelq = () => {
      selCxAllq({needDepartment: ''})
    }
    //下拉数据
    const optionsq = ref<any>(pageData.nameListq)
    const loadingq = ref(false)
    const handleSearchq = (value: any) => {
      if (value) {
        const ob = {needDepartment: value}
        loadingq.value = true
        window.setTimeout(() => {
          selCxAllq(ob)
          optionsq.value = pageData.nameListq
          loadingq.value = false
        }, 200)
      } else {
        optionsq.value = []
      }
    }

    //下拉框查询
    function selCxAllq(val: any) {
      post({
        url: 'dwPurchase/purchaseNeed/getDropValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          // (data as string[]).splice(0, 0, "全部");
          pageData.nameListq = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    //下拉框得到焦点
    const focusSelqs = () => {
      selCxAllqs({materialName: '', auditState: 1})
    }
    //下拉数据
    const optionsqs = ref<any>(pageData.nameListqs)
    const loadingqs = ref(false)
    const handleSearchqs = (value: any) => {
      if (value) {
        const ob = {materialName: value, auditState: 1}
        loadingqs.value = true

        selCxAllq(ob)
        optionsqs.value = pageData.nameListqs
        loadingqs.value = false
      } else {
        options.value = []
      }
    }

    //下拉框查询
    function selCxAllqs(val: any) {
      post({
        url: 'dwPurchase/MaterialInfo/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          // (data as string[]).splice(0, 0, "全部");
          pageData.nameListqs = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    const compareDate = (dateTime1: any, dateTime2: any) => {
      var formatDate1 = new Date(dateTime1)
      var formatDate2 = new Date(dateTime2)
      if (formatDate1 > formatDate2) {
        return true
      } else {
        return false
      }
    }

    function doRefreshs() {
      // getFirmGroup()
      pageData.pageLoading = true
      var startDate = pageData.dropDownDataqszs.startDate
      var endDate = pageData.dropDownDataqszs.endDate
      // let data1 = startDate
      // let data2 = endDate
      // var formatDate1 = new Date(startDate)
      // var formatDate2 = new Date(endDate)
      // if (formatDate1 > formatDate2) {
      //   startDate = data2 ? data2 + ' 00:00:00' : ''
      //   endDate = data1 ? data1 + ' 23:59:59' : ''
      // } else {
      //   startDate = data1 ? data1 + ' 00:00:00' : ''
      //   endDate = data2 ? data2 + ' 23:59:59' : ''
      // }
      post({
        url: 'dwPurchase/purchaseNeed/getInfo',
        data: {
          purchaseNeedCode: pageData.dropDownData123,
          processedState: 0,
          auditState: 1,
          needDepartmentId: isDatas.is1,
          needPerson: isDatas.is2,
          needType: isDatas.is3,
          warehouseName: isDatas.is4,
          materialName: isDatas.is5,
          specName: isDatas.is6,
          needCompany: isDatas.is,
          startDate: compareDate(startDate, endDate) == true ? endDate : startDate,
          endDate: compareDate(startDate, endDate) == true ? startDate : endDate,
          auditDate: isDatas.auditDate
        },
      })
          .then(({data, code}: any) => {
            if (code === 200) {
              table.handleSuccess(data)
              gridOption.value.setRowData(data)
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
    }

    const selectSh = () => {
      pagination.page = 1
      doRefreshs()
    }

    const timer = ref<any>()
    const tableColumns = useTableColumn([
      {
        title: '需求公司',
        key: 'needCompanys',
        dataIndex: 'needCompanys',
        width: 150,
      },
      {
        title: '需求部门',
        key: 'needDepartment',
        dataIndex: 'needDepartment',
        width: 150,
      },
      {
        title: '需求单号',
        key: 'purchaseNeedCode',
        dataIndex: 'purchaseNeedCode',
        width: 150,
      },
      {
        title: '开单日期',
        key: 'needCreateDate',
        dataIndex: 'needCreateDate',
        width: 180,
      },
      {
        title: '需求人',
        key: 'needPerson',
        dataIndex: 'needPerson',
        width: 150,
      },
      {
        title: '需求类型',
        key: 'needType',
        dataIndex: 'needType',
        slotName: 'needType',
        width: 150,
      },
      {
        title: '采购公司',
        key: 'useCompanys',
        dataIndex: 'useCompanys',
        width: 150,
      },
      {
        title: '采购部门',
        key: 'useDepartment',
        dataIndex: 'useDepartment',
        width: 150,
      },
      {
        title: '仓库名称',
        key: 'warehouseName',
        dataIndex: 'warehouseName',
        width: 150,
      },
      {
        title: '物料编号',
        key: 'materialCode',
        dataIndex: 'materialCode',
        width: 150,
      },
      {
        title: '物料名称',
        key: 'materialName',
        dataIndex: 'materialName',
        width: 150,
      },
      {
        title: '规格',
        key: 'specName',
        dataIndex: 'specName',
        width: 150,
      },

      {
        title: '单位',
        key: 'unitName',
        dataIndex: 'unitName',
        width: 150,
      },
      {
        title: '需求数量',
        key: 'needNum',
        dataIndex: 'needNum',
        width: 150,
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        width: 150,
      },
      {
        title: '需求说明',
        key: 'needInstruction',
        dataIndex: 'needInstruction',
        width: 150,
      },
      // {
      //   title: '驳回原因',
      //   key: 'rejectCause',
      //   dataIndex: 'rejectCause',
      //   width: 150,
      // },
      {
        title: '创建人',
        key: 'updateName',
        dataIndex: 'updateName',
        width: 150,
      },
      {
        title: '创建时间',
        key: 'updateTime',
        dataIndex: 'updateTime',
        width: 200,
      },
      // {
      //     title: "提交状态",
      //     key: "submitState",
      //     dataIndex: "submitState",
      //     width: 150,
      //     fixed: 'right',
      //     slotName: "submitState",
      // },
      // {
      //     title: "操作",
      //     key: "action",
      //     dataIndex: "action",
      //     slotName: "action",
      //     width: 100,
      //     fixed: 'right'
      // },
    ])

    const tableColumns6 = useTableColumn([
      {
        title: '需求公司',
        key: 'needCompanys',
        dataIndex: 'needCompanys',
        width: 150,
      },
      {
        title: '需求部门',
        key: 'needDepartment',
        dataIndex: 'needDepartment',
        width: 150,
      },
      {
        title: '需求单号',
        key: 'purchaseNeedCode',
        dataIndex: 'purchaseNeedCode',
        width: 150,
      },
      {
        title: '开单日期',
        key: 'needCreateDate',
        dataIndex: 'needCreateDate',
        width: 180,
      },
      {
        title: '需求人',
        key: 'needPerson',
        dataIndex: 'needPerson',
        width: 150,
      },
      {
        title: '需求类型',
        key: 'needType',
        dataIndex: 'needType',
        slotName: 'needType',
        width: 150,
      },
      {
        title: '采购公司',
        key: 'useCompanys',
        dataIndex: 'useCompanys',
        width: 150,
      },
      {
        title: '采购部门',
        key: 'useDepartment',
        dataIndex: 'useDepartment',
        width: 150,
      },
      {
        title: '仓库名称',
        key: 'warehouseName',
        dataIndex: 'warehouseName',
        width: 150,
      },
      {
        title: '物料名称',
        key: 'materialName',
        dataIndex: 'materialName',
        width: 150,
      },
      {
        title: '规格',
        key: 'specName',
        dataIndex: 'specName',
        width: 150,
      },

      {
        title: '单位',
        key: 'unitName',
        dataIndex: 'unitName',
        width: 150,
      },
      {
        title: '需求数量',
        key: 'needNum',
        dataIndex: 'needNum',
        width: 150,
      },
      {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        width: 150,
      },
      // {
      //   title: '驳回原因',
      //   key: 'rejectCause',
      //   dataIndex: 'rejectCause',
      //   width: 150,
      // },
      {
        title: '需求说明',
        key: 'needInstruction',
        dataIndex: 'needInstruction',
        width: 150,
      },
      {
        title: '创建人',
        key: 'updateName',
        dataIndex: 'updateName',
        width: 150,
      },
      {
        title: '创建时间',
        key: 'updateTime',
        dataIndex: 'updateTime',
        width: 200,
      },
      // {
      //     title: "提交状态",
      //     key: "submitState",
      //     dataIndex: "submitState",
      //     width: 150,
      //     fixed: 'right',
      //     slotName: "submitState",
      // },
      // {
      //     title: "操作",
      //     key: "action",
      //     dataIndex: "action",
      //     slotName: "action",
      //     width: 100,
      //     fixed: 'right'
      // },
    ])

    let visible = ref(false)
    const tqxqd = () => {
      pageData.dropDownData = ''
      selectedRowKeys.value = []

      visible.value = true
    }
    let detailUID: any
    const handleBeforeOk = () => {
      getFirmGroup()
      if (gridOption.value.getSelectedRows().length == 0) {
        Message.error('请先勾选数据')
        return
      }
      let selectData = gridOption.value.getSelectedRows()
      if (!selectData.every((item: any) => item.useCompanys === selectData[0].useCompanys)) {
        Message.error('请勾选相同的采购公司')
        return
      }
      // let tmp: any = null
      // const bool = gridOption.value.getSelectedRows().every((c: any) => {
      //   if (tmp === null) {
      //     tmp = c
      //     return true;
      //   } else {
      //     return tmp.useCompanys === c.useCompanys
      //   }
      // })
      // if (!bool) {
      //   Message.error('请勾选相同公司')
      //   return
      // }
      let detailUIDs: any = []
      gridOption.value.getSelectedRows().forEach((item: any) => {
        detailUIDs.push(item.uid)
      })
      getFirmGroup()
      getBmGroup1(dataForm.useCompany)
      // 加锁
      post({
        url: 'dwPurchase/PurchaseApply/redisOut',
        data: detailUIDs,
      }).then(({data, code, message}: any) => {
        if (code === 200) {
          //打开弹窗

          post({
            url: 'dwPurchase/PurchaseApply/getAutomaticInfo',
            data: gridOption.value.getSelectedRows(),
          }).then((resss: any) => {
            if (resss.code == 200) {
              const {useCompany, useCompanys} = resss.data.hashMap[0]
              dataForm.applyPerson = resss.data.applyPerson
              dataForm.applyCode = resss.data.maxApplyCode
              dataForm.useCompany = useCompany
              dataForm.useCompanys = useCompanys
              // dataForm.useDepartment = useDepartment
              // dataForm.useDepartmentId = useDepartmentId
              getBmGroup1(dataForm.useCompany)
              pageData.tqDataList = []
              if (gridOption.value.getSelectedRows().length == 0) {
                visible.value = true
                Message.error('请勾选数据')
                return
              }
              pageData1.title = '创建申购单'

              timer.value = setInterval(() => {
                post({
                  url: 'dwPurchase/PurchaseApply/redisOut',
                  data: detailUIDs,
                })
              }, 30000)
              // pageData.tqDataList = table.dataList.filter(function (o) {
              //   return detailUIDs.includes(o['detailUID'])
              // })
              // let ob={"code1":[{id:1,name:2},{id:1,name:3},],
              // "code2":[{id:1,name:2},{id:1,name:3},]}
              // list.forEach(function(o:any){
              //   ob[o.code]=[]
              // })
              // ob.map((o:any)=>{return o.})
              pageData.tqDataList = [...resss.data.hashMap]
              const {hashMap} = resss.data
              pageData.tqDataList.map((item, index) => {
                if (
                    item.materialCode == hashMap[index].materialCode &&
                    item.materialName == hashMap[index].materialName
                ) {
                  item.applyNum = hashMap[index].needNum
                }
                // visible.value = false
              })

              pageData.tqDataList.forEach((item: any, index: any) => {
                pageData.tqDataList.forEach((item1: any) => {
                  if (item.materialCode == item1.materialCode) {
                    // item.applyNum = item1.needNum
                    item.unit = item1.unitName
                  }
                })
              })
              ckNum()
              // pageData1.showAdd = true
              // detailUID = []
              // pageData.tqDataList.forEach((item: any) => {
              //   detailUID.push(item.detailUID)
              // })
              //构建合并数据 的表格数据
              // let dataObList: any = []
              // let dataOb = {}
              // for (let i = 0; i < pageData.tqDataList.length; i++) {
              //   let key =
              //     pageData.tqDataList[i]['materialName'] +
              //     '_' +
              //     pageData.tqDataList[i]['specName'] +
              //     '_' +
              //     pageData.tqDataList[i]['unitName']
              //   if (dataOb[key] == undefined) {
              //     dataOb[key] = {}
              //     dataOb[key]['needNum'] = parseFloat(pageData.tqDataList[i]['needNum'])
              //     dataOb[key]['needCode'] = pageData.tqDataList[i]['needCode']
              //     dataOb[key]['detailUID'] = pageData.tqDataList[i]['detailUID']
              //     dataOb[key]['warehouseName'] = pageData.tqDataList[i]['warehouseName']
              //     dataOb[key]['materialCode'] = pageData.tqDataList[i]['materialCode']
              //     dataOb[key]['materialName'] = pageData.tqDataList[i]['materialName']
              //     dataOb[key]['needCode'] = pageData.tqDataList[i]['needCode']
              //     dataOb[key]['specName'] = pageData.tqDataList[i]['specName']
              //     dataOb[key]['batchName'] = pageData.tqDataList[i]['batchName']
              //     dataOb[key]['unit'] = pageData.tqDataList[i]['unitName']
              //     dataOb[key]['applyNum'] = parseFloat(pageData.tqDataList[i]['needNum'])
              //     // dataOb[key]['stockNum'] = parseFloat(pageData.tqDataList[i]['stockNum'])
              //     dataOb[key]['remark'] = pageData.tqDataList[i]['remark']
              //     dataOb[key]['useDepartment'] = pageData.tqDataList[i]['useDepartment'] + ", "
              //     dataOb[key]['useDepartmentId'] = pageData.tqDataList[i]['useDepartmentId'] + "/"
              //   } else {
              //     dataOb[key]['needNum'] += parseFloat(pageData.tqDataList[i]['needNum'])
              //     // dataOb[key]['stockNum'] += parseFloat(pageData.tqDataList[i]['stockNum'])
              //     if (dataOb[key]['remark'] == null) {
              //       dataOb[key]['remark'] += pageData.tqDataList[i]['remark']
              //     } else {
              //       dataOb[key]['remark'] += pageData.tqDataList[i]['remark'] + ", "
              //     }
              //     dataOb[key]['useDepartment'] += pageData.tqDataList[i]['useDepartment'] + ", "
              //     // dataOb[key]['useDepartmentId'] += pageData.tqDataList[i]['useDepartmentId'] + "/"
              //   }
              // }
              // for (const key in dataOb) {
              //   var ob = {}
              //   ob['materialCode'] = dataOb[key]['materialCode']
              //   ob['materialName'] = dataOb[key]['materialName']
              //   ob['specName'] = dataOb[key]['specName']
              //   ob['warehouseName'] = dataOb[key]['warehouseName']
              //   ob['unit'] = dataOb[key]['unit']
              //   ob['needNum'] = dataOb[key]['needNum']
              //   ob['id'] = dataOb[key]['id']
              //   ob['needCode'] = dataOb[key]['needCode']
              //   ob['detailUID'] = dataOb[key]['detailUID']
              //   ob['applyNum'] = dataOb[key]['needNum']
              //   // ob['stockNum'] = dataOb[key]['stockNum']
              //   ob['batchName'] = dataOb[key]['batchName']
              //   ob['remark'] = dataOb[key]['remark']
              //   ob['useDepartment'] = dataOb[key]['useDepartment']
              //   ob['useDepartmentId'] = dataOb[key]['useDepartmentId']
              //   // dataForm.useDepartment = ob['useDepartment']
              //   // dataForm.useDepartmentId = ob['useDepartmentId']
              //   dataObList.push(ob)
              // }
              // console.log(pageData.tqDataList.map((o:any)=>{return o.stockNum}))
              // gridOptionsz111.value.getSelectedRows()([...data.hashMap])
              // pageData.tqDataList = dataObList

              // pageData1.showAdd = true
              // pageData.tqDataList.filter((item: any) => {
              //   if (item.applyNum <= (item.stockNum ==undefined ? 0 : item.stockNum) ) {
              //     Message.error('不需要创建申购单，请直接前往领料单')
              //     return
              //   }else{
              //     pageData1.showAdd = true
              //   }
              // })
            }
          })
        } else {
          if (data != '') {
            let purchaseNeedCode = ''
            let materialName = ''
            let StrUname = ''
            data.forEach(function (o: any) {
              if (purchaseNeedCode == '') {
                purchaseNeedCode = o['purchaseNeedCode']
              } else {
                if (purchaseNeedCode.indexOf(o['purchaseNeedCode']) == -1) {
                  purchaseNeedCode += '、' + o['purchaseNeedCode']
                }
              }
              if (materialName == '') {
                materialName = o['materialName']
              } else {
                if (materialName.indexOf(o['materialName']) == -1) {
                  materialName += '、' + o['materialName']
                }
              }
              if (StrUname == '') {
                StrUname = o['name']
              } else {
                if (StrUname.indexOf(o['name']) == -1) {
                  StrUname += '、' + o['name']
                }
              }
            })
            Message.error({
              content:
                  '您勾选的' +
                  purchaseNeedCode +
                  '单号里的' +
                  materialName +
                  '物料正在被' +
                  StrUname +
                  '使用中！！！',
              duration: 10000,
            })
          } else {
            Message.error({
              content: message,
              duration: 10000,
            })
          }
        }
      })

      // //筛选出物料
      // let codeList: any = [];
      // let dataList1 = table.dataList.filter(function (o) {
      //     return selectedRowKeys.value.includes(o["detailUID"])
      // });
      // if (dataList1.length > 0) {
      //     dataList1.forEach(function (o: any) {
      //         if (!codeList.includes(o['purchaseNeedCode'])) {
      //             codeList.push(o['purchaseNeedCode'])
      //         }
      //     })
      // }
      // //判断单号是否已选择过
      // if (isDataLists.value.length > 0) {
      //     var list = isDataLists.value.filter(function (o: any) {
      //         return codeList.includes(o.detailUID)
      //     })
      //     if (list.length > 0) {
      //         Message.warning({
      //             content: "此" + list[0]['detailUID'] + "物料已被提取过",
      //             duration: 5000,
      //         });
      //         visible.value = true
      //         return
      //     }
      // }
      // pageData.xqDataList = pageData.xqDataList.concat(dataList1);
      // selectedRowKeys.value.forEach((item: any) => {
      //     table.dataList.forEach((items: any) => {
      //         if (item == items.detailUID) {

      //             isDataLists.value.push({
      //                 id: items.id,
      //                 detailUID: items.detailUID,
      //                 warehouseName: items.warehouseName,
      //                 needCode: items.purchaseNeedCode,
      //                 materialName: items.materialName,
      //                 specName: items.specName,
      //                 batchName: items.batchName,
      //                 unit: items.unitName,
      //                 needNum: items.needNum
      //             })
      //         }
      //     })
      // })
    }
    window.onbeforeunload = function () {
      onClose()
      setTimeout(() => {
      }, 30000)
    }
    onUnmounted(() => {
      onClose()
    })
    //关闭定时器
    const onClose = () => {
      let detailUIDs: any = []
      gridOption.value.getSelectedRows().forEach((item: any) => {
        detailUIDs.push(item.detailUID)
      })
      clearInterval(timer.value)
      post({
        url: 'dwPurchase/PurchaseApply/upRedis',
        data: detailUIDs,
      })
      detailUID = []
    }

    //tabs切换
    const changetabs = (key: any) => {
      // table.handleSuccess([])
      pageData.isKey = key
      selectedRowKeys.value = []
      if (key == 1) {
        selectSh()
      } else if (key == 2) {
        cxAllInfo()
      } else if (key == 3) {
        cxAllYtj()
      }
    }
    const visible1 = ref(false)
    const visible1s = ref(false)
    //查看详情按钮
    const cxDetails = (record: any) => {
      visible1.value = true
      post({
        url: 'dwPurchase/PurchaseApply/getDetail',
        data: {
          page: 1,
          size: pagination.pageSize,
          // "auditState": 0,
          // "submitState": 0,
          applyCode: record['applyCode'],
          rejectState: 0,
        },
      }).then(({data, code}: any) => {
        if (code === 200) {
          pageData.isDetailsList = data[0]['purchaseApplyDetail']
          // pageData.isDetailsList = data[0]['purchaseApply']
          ckNum3()
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }
    //提交需求单
    const submit = (num: any) => {
      // if (selectedRowKeys.value.length === 0) {
      //     Message.warning({
      //         content: '请先勾选',
      //         duration: 5000
      //     })
      //     return
      // }
      // let list = [];
      // for (let i = 0; i < selectedRowKeys.value.length; i++) {
      //     var ob = {}
      //     ob['id'] = selectedRowKeys.value[i]
      //     ob['confirmState'] = num
      //     list.push(ob)
      // }

      if (pageData.xqDataList.length == 0) {
        Message.warning({
          content: '请先提取需求单!',
          duration: 5000,
        })
        return
      }
      post({
        url: 'dwPurchase/PurchaseApply/insert',
        data: {
          ...dataForm,
          purchaseApplyDetail: pageData.xqDataList,
        },
      }).then((res: any) => {
        if (res.code === 200) {
          doRefresh()
          selectedRowKeys.value = []
        } else {
          Message.error({
            content: res.message,
            duration: 5000,
          })
        }
      })
    }

    const isDatas: any = reactive({
      is1: '',
      is1Array: [],
      is2: '',
      is2Array: [],
      is3: '',
      is3Array: [],
      is4: '',
      is4Array: [],
      is5: '',
      is5Array: [],
      is6: '',
      is6Array: [],
      is: '',
      iss: '',
    })

    function cx(val: any, num: Number) {
      post({
        url: 'dwPurchase/purchaseNeed/getValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          switch (num) {
            case 1:
              isDatas.is1Array = data
              break
            case 2:
              isDatas.is2Array = data
              break
            case 3:
              isDatas.is3Array = data
              break
            case 4:
              isDatas.is4Array = data
              break
            case 5:
              isDatas.is5Array = data
              break
            case 6:
              isDatas.is6Array = data
              break
          }
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    const xuQiu = (val: any) => {
      cx({needDepartment: val, processedState: 0, auditState: 1}, 1)
    }
    const xuQius = () => {
      cx({needDepartment: '', processedState: 0, auditState: 1}, 1)
    }
    const xuQiur = (val: any) => {
      cx({needPerson: val, processedState: 0, auditState: 1}, 2)
    }
    const xuQiurs = () => {
      cx({needPerson: '', processedState: 0, auditState: 1}, 2)
    }
    const xuQiuLeix = (val: any) => {
      cx({needType: val, processedState: 0, auditState: 1}, 3)
    }
    const xuQiuLeixs = () => {
      cx({needType: '', processedState: 0, auditState: 1}, 3)
    }
    const xuQiuCk = (val: any) => {
      cx({warehouseName: val, processedState: 0, auditState: 1}, 4)
    }
    const xuQiuCks = () => {
      cx({warehouseName: '', processedState: 0, auditState: 1}, 4)
    }

    function cxs(val: any, num: Number) {
      post({
        url: 'dwPurchase/purchaseNeedDetail/getValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          switch (num) {
            case 5:
              isDatas.is5Array = data
              break
            case 6:
              isDatas.is6Array = data
              break
          }
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    const xuQiuWl = (val: any) => {
      cxs({materialName: val, processedState: 0, auditState: 1}, 5)
    }
    const xuQiuWls = () => {
      cxs({materialName: '', processedState: 0, auditState: 1}, 5)
    }
    const xuQiuGg = (val: any) => {
      cxs({specName: val, processedState: 0, auditState: 1}, 6)
    }
    const xuQiuGgs = () => {
      cxs({specName: '', processedState: 0, auditState: 1}, 6)
    }
    const cancelDelet = () => {
      post({
        url: 'dwPurchase/PurchaseApply/upRedis',
        data: detailUID,
      })
      ;(pageData1.showAdd = false), formRef.value?.resetFields()
      for (let item in dataForm) {
        dataForm[item] = ''
      }
    }

    //拿到所有公司
    // const foucusUseFrim = (num: any) => {
    //   let ob = {}
    //   if (num == 1) {
    //     ob['firmName'] = ''
    //     ob['department'] = ''
    //     // ob['firmTypeId'] = ""
    //   }
    //   if (num == 2) {
    //     if (dataForm.applyCompany !== '' && dataForm.applyCompany !== undefined) {
    //       let list = pageData.firmList.filter(function (o: any) {
    //         return o['id'] == dataForm.applyCompany
    //       })
    //       if (list.length > 0) {
    //         ob['firmName'] = list[0]['firmName']
    //         dataForm.applyCompanys = list[0]['typeName']
    //           ? list[0]['typeName'] + '-' + list[0]['firmName']
    //           : list[0]['firmName']
    //         ob['department'] = list[0]['department']
    //         ob['firmTypeId'] = list[0]['firmTypeId']
    //       }
    //     } else {
    //       Message.warning({
    //         content: '请先选择申购公司',
    //         duration: 5000,
    //       })
    //     }
    //   }
    //   if (num == 3) {
    //     ob['firmName'] = ''
    //     ob['department'] = ''
    //     // ob['firmTypeId'] = ""
    //   }
    //   if (num == 4) {
    //     if (dataForm.useCompany !== '' && dataForm.useCompany !== undefined) {
    //       let list = pageData.firmList.filter(function (o: any) {
    //         return o['id'] == dataForm.useCompany
    //       })
    //       if (list.length > 0) {
    //         ob['firmName'] = list[0]['firmName']
    //         dataForm.useCompanys = list[0]['typeName']
    //           ? list[0]['typeName'] + '-' + list[0]['firmName']
    //           : list[0]['firmName']
    //         ob['department'] = list[0]['department']
    //         ob['firmTypeId'] = list[0]['firmTypeId']
    //       }
    //     } else {
    //       Message.warning({
    //         content: '请先选择采购公司',
    //         duration: 5000,
    //       })
    //     }
    //   }
    //   //搜索框公司
    //   if (num == 5) {
    //     ob['firmName'] = ''
    //     ob['department'] = ''
    //   }
    //   if (num == 6) {
    //     if (isDatas.is !== '' && isDatas.is !== undefined) {
    //       let list = pageData.nameListq1.filter(function (o: any) {
    //         return o['id'] == isDatas.is
    //       })
    //       ob['firmName'] = list[0]['firmName']
    //       isDatas.iss = list[0]['typeName']
    //         ? list[0]['typeName'] + '-' + list[0]['firmName']
    //         : list[0]['firmName']
    //       ob['department'] = list[0]['department']
    //       ob['firmTypeId'] = list[0]['firmTypeId']
    //     } else {
    //       Message.warning({
    //         content: '请先选择需求公司',
    //         duration: 5000,
    //       })
    //     }
    //   }
    //   getFrimList(ob, num)
    // }
    const options2 = ref(pageData.firmList)
    const loading2 = ref(false)

    const handleSearch2 = (value: any) => {
      if (value) {
        loading2.value = true

        options2.value = pageData.firmList
        loading2.value = false
      } else {
        options2.value = []
      }
    }
    // function getFrimList(ob: any, nums: any) {
    //   post({
    //     url: 'org/firmGroup/getFirmInfoByMap',
    //     data: ob,
    //   }).then((result: any) => {
    //     if (result.code === 200) {
    //       if (nums == 1) {
    //         pageData.firmList = result.data
    //       }
    //       if (nums == 2) {
    //         pageData.bmList = result.data
    //       }
    //       if (nums == 3) {
    //         pageData.firmListsy = result.data
    //       }
    //       if (nums == 4) {
    //         pageData.bmListsy = result.data
    //       }
    //       if (nums == 5) {
    //         pageData.nameListq1 = result.data
    //       }
    //       if (nums == 6) {
    //         pageData.nameListq = result.data
    //       }
    //     } else {
    //       Message.error(result.message)
    //     }
    //   })
    // }
    // const casOb = ref()
    // const casOb1 = ref()
    // //公司改变 部门为=空
    // const changeGs = (num: any, val: any) => {
    //   if (num == 1) {
    //     dataForm.applyDepartment = ''
    //   } else {
    //     dataForm.useDepartment = ''
    //   }
    //   //拿到选中的这个节点数组
    //   setTimeout(function () {

    //     if (casOb.value.selectViewValue.length != 0) {
    //       pageData.title = casOb.value.selectViewValue[0]['label']
    //       dataForm.applyCompany = casOb.value.selectViewValue[0]['label']
    //     }

    //   }, 100)

    //   getBmGroup(val)
    //   ygselect("")
    // }
    // //部门改变
    // const cascaderChange1 = (val: any) => {
    //   //拿到选中的这个节点数组
    //   setTimeout(function () {

    //     if (casOb1.value.selectViewValue.length != 0) {
    //       pageData.title1 = casOb1.value.selectViewValue[0]['label']
    //       dataForm.applyDepartment = casOb.value.selectViewValue[0]['label']
    //     }
    //   }, 100)
    //   ygselect(val)
    // }
    // // 获取公司列表
    // const getFirmGroup = () => {
    //   post({
    //     url: 'org/baCompany/getTreeCompanyByUser',
    //     data: {}
    //   }).then(({ code, data }) => {
    //     if (code === 200) {
    //       pageData.firmList = data
    //     }
    //   })
    // }
    // // 获取部门列表
    // const getBmGroup = (val: any) => {
    //   post({
    //     url: 'org/baCompany/getDepartmentTree?companyId=' + val,
    //   })
    //     .then((result) => {
    //       if (result.code === 200) {
    //         pageData.bmList = result.data
    //       }

    //     })

    // }
    const ygselectlist = ref<any[]>([])

    async function ygselect(v: string) {
      pageData.loading = true
      pageData.loading1 = true
      post({
        url: 'org/hrEmployee/getList',
        data: {
          deleteState: 0,
          obsoleteState: 0,
          company_id: dataForm.applyCompany,
          department_id: v,
        },
      })
          .then(({data, code}) => {
            if (code === 200) {
              ygselectlist.value = data
            }
          })
          .finally(() => {
            pageData.loading = false
            pageData.loading1 = false
          })
    }

    const gridOption = ref()
    const gridReady = (params: any) => {
      gridOption.value = params.api
    }
    const defaultColDef = {
      sortable: true,
      resizable: true,
      filter: true,
    }
    let tc: any[] = tableColumns.map((o) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
        tooltipField: o.key,
      }
      if (o.slotName === 'needType') {
        obj['filterParams'] = {
          valueFormatter: function (params: any) {
            return params.value == '0'
                ? '加急'
                : params.value == '1'
                    ? '计划'
                    : params.value == '2'
                        ? '临时'
                        : ''
          },
        }
        obj['cellRenderer'] = {
          template: `
            <a-space>
              <div style="color:red;font-weight: bolder;" v-if="isDatas.needType == '0'">
                加急
              </div>
              <div style="color:green;font-weight: bolder;" v-if="isDatas.needType == '1'">
                计划
              </div>
              <div style="color:blue;font-weight: bolder;" v-if="isDatas.needType == '2'">
                临时
              </div>
            </a-space>`,
          setup(props: any) {
            const isDatas = ref(props.params.data)
            return {
              isDatas,
            }
          },
        }
      }
      return obj
    })

    let a = [
      {
        showRowGroup: 'hide_def',
        headerName: '',
        checkboxSelection: true,
        headerCheckboxSelection: true,
        pinned: 'left',
        width: 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: 'left',
      },
    ]
    tc = a.concat(tc)

    const gridOptions = ref()
    const gridReadys = (params: any) => {
      gridOptions.value = params.api
    }
    const defaultColDefs = {
      sortable: true,
      resizable: true,
      filter: true,
    }
    let tcs: any[] = tableColumns1.map((o) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
        tooltipField: o.key,
      }
      if (o.slotName === 'action') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = 130
        obj['cellRenderer'] = {
          template: `
            <a-space>
              <a-tag class="tagCss" v-if="(isDtas.auditState != 1) && e" @click="a1">修改</a-tag>
              <a-tag class="tagCss" v-if="(isDtas.auditState == 1) && e2" disabled style="color:#d1d1d1 !important">
                修改
              </a-tag>
              <a-tag class="tagCss" @click="a2" v-if="f">详情</a-tag>
            </a-space>
          `,
          setup(props: any) {
            const isDtas = ref(props.params.data)
            const a1 = () => {
              editHandler(props.params.data)
            }
            const a2 = () => {
              cxDetails(props.params.data)
            }
            return {
              e: pageData.isEdit,
              e2: pageData.isEdit,
              f: pageData.isDetail,
              isDtas,
              a1,
              a2,
            }
          },
        }
      }
      if (o.slotName === 'applyType') {
        obj['filterParams'] = {
          valueFormatter: function (params: any) {
            return params.value == '0'
                ? '加急'
                : params.value == '1'
                    ? '计划'
                    : params.value == '2'
                        ? '临时'
                        : ''
          },
        }
        obj['cellRenderer'] = {
          template: `
            <a-space>
              <div style="color:red;font-weight: bolder;" v-if="isDatas.applyType == '0'">
                加急
              </div>
              <div style="color:green;font-weight: bolder;" v-if="isDatas.applyType == '1'">
                计划
              </div>
              <div style="color:blue;font-weight: bolder;" v-if="isDatas.applyType == '2'">
                临时
              </div>
            </a-space>`,
          setup(props: any) {
            const isDatas = ref(props.params.data)
            return {
              isDatas,
            }
          },
        }
      }
      return obj
    })

    let as = [
      {
        showRowGroup: 'hide_def',
        headerName: '',
        checkboxSelection: true,
        headerCheckboxSelection: true,
        pinned: 'left',
        width: 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: 'left',
      },
    ]
    tcs = as.concat(tcs)

    const gridOptionsz = ref()
    const gridReadysz = (params: any) => {
      gridOptionsz.value = params.api
    }
    const defaultColDefsz = {
      sortable: true,
      resizable: true,
      filter: true,
    }
    let tcsz: any[] = tableColumns6.map((o) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
        tooltipField: o.key,
      }
      if (o.slotName === 'needType') {
        obj['filterParams'] = {
          valueFormatter: function (params: any) {
            return params.value == '0'
                ? '加急'
                : params.value == '1'
                    ? '计划'
                    : params.value == '2'
                        ? '临时'
                        : ''
          },
        }
        obj['cellRenderer'] = {
          template: `
            <a-space>
              <div style="color:red;font-weight: bolder;" v-if="isDatas.needType == '0'">
                加急
              </div>
              <div style="color:green;font-weight: bolder;" v-if="isDatas.needType == '1'">
                计划
              </div>
              <div style="color:blue;font-weight: bolder;" v-if="isDatas.needType == '2'">
                临时
              </div>
            </a-space>`,
          setup(props: any) {
            const isDatas = ref(props.params.data)
            return {
              isDatas,
            }
          },
        }
      }
      return obj
    })

    let asz = [
      {
        showRowGroup: 'hide_def',
        headerName: '',
        checkboxSelection: true,
        headerCheckboxSelection: true,
        pinned: 'left',
        width: 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: 'left',
      },
    ]
    tcsz = asz.concat(tcsz)

    const gridOptionsz111 = ref()
    const gridReadysz111 = (params: any) => {
      gridOptionsz111.value = params.api
      gridOptionsz111.value.sizeColumnsToFit()
    }
    const defaultColDefsz111 = {
      sortable: true,
      resizable: true,
      filter: true,
      flex: 1,
    }
    let tcsz111: any[] = tableColumns2.map((o) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
        tooltipField: o.key,
      }
      if (o.slotName === 'applyNum') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['cellRenderer'] = {
          template: `
            <a-input-number v-model="isDtas.applyNum" class="input-demo bacClass" :min="0"
                            :max="10000000000000000000"/>`,
          setup(props: any) {
            const isDtas = ref(props.params.data)
            return {
              isDtas,
            }
          },
        }
      }
      if (o.slotName === 'stockNum') {
        obj['cellRenderer'] = {
          template: `
            <div>{{ val }}</div>`,
          setup(props: any) {
            let val = ref()
            val.value = props.params.data.stockNum
            return {
              val,
            }
          },
        }
      }
      if (o.slotName === 'remark') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['cellRenderer'] = {
          template: `
            <a-input class="bacClass" v-model="isDtas.remark"/>
          `,
          setup(props: any) {
            const isDtas = ref(props.params.data)
            return {
              isDtas,
            }
          },
        }
      }
      // if (o.slotName === 'act') {
      //   obj['resizable'] = false
      //   obj['filter'] = false
      //   obj['sortable'] = false
      //   obj["lockPosition"] = "right"
      //   obj["width"] = 80
      //   obj['cellRenderer'] = {
      //     template: `<el-button style="color:#165dff;" link @click="b">驳回</el-button>`,
      //     setup(props: any) {
      //       const b = () => {
      //         overrule()
      //       }
      //       return {
      //         b
      //       }
      //     }

      //   }
      // }
      return obj
    })
    let asz111 = [
      {
        showRowGroup: 'hide_def',
        headerName: '',
        checkboxSelection: true,
        headerCheckboxSelection: true,
        pinned: 'left',
        width: 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: 'left',
      },
    ]
    tcsz111 = asz111.concat(tcsz111)
    const isDtasZh = ref(false)

    const cancelDelets = () => {
      for (let item in dataForm) {
        dataForm[item] = ''
      }
      isDataListss.value = []
      isDtasZh.value = false
    }

    const sideOkss = () => {
      let isKong = false
      isDataListss.value.forEach(function (o: any) {
        if (sgTitels.value == '新增申购单') {
          o['id'] = null
        }
        if (o['needNum'] == 0) {
          isKong = true
        }
      })
      for (let i = 0; i < isDataListss.value.length; i++) {
        let o: any = isDataListss.value[i]
        if (o['materialCode'] == '' || o['materialCode'] == undefined) {
          Message.warning({
            content: '请将物料编号填写完',
            duration: 5000,
          })
          return
        }
        if (o['materialName'] == '' || o['materialName'] == undefined) {
          Message.warning({
            content: '请将物料名称填写完',
            duration: 5000,
          })
          return
        }
        // if (o['specName'] == '' || o['specName'] == undefined) {
        //   Message.warning({
        //     content: '请将规格填写完',
        //     duration: 5000,
        //   })
        //   return
        // }
        if (o['unit'] == '' || o['unit'] == undefined) {
          Message.warning({
            content: '请将单位填写完',
            duration: 5000,
          })
          return
        }
        // if (o['needNum'] == '' || o['needNum'] == undefined) {
        //   Message.warning({
        //     content: '请将必填字段填写完',
        //     duration: 5000,
        //   })
        //   return
        // }
        if (o['applyNum'] == '' || o['applyNum'] == undefined) {
          Message.warning({
            content: '请将申购单数量填写完',
            duration: 5000,
          })
          return
        }
        // if(o['stockNum'] == '' || o['stockNum'] == undefined){
        //     Message.warning({
        //     content: "请将必填字段填写完",
        //     duration: 5000,
        // });
        // return
        // }
      }

      // if (
      //   dataForm['applyDepartment'] == '' ||
      //   dataForm['applyType'] == '' ||
      //   dataForm['planDeliveryDate'] == ''
      // ) {
      //   Message.warning({
      //     content: '请将必填字段填写完',
      //     duration: 5000,
      //   })
      //   return
      // }
      // if (isKong) {
      //   Message.warning({
      //     content: '填写的数量必须大于0',
      //     duration: 5000,
      //   })
      //   return
      // }
      let condition = isDataListss.value.some((item: { materialCode: string }, index: number) => {
        if (index !== 0) {
          return item.materialCode === isDataListss.value[0].materialCode
        }
      })
      if (condition) {
        Message.warning({
          content: '不能添加同样的物料',
          duration: 5000,
        })
        return
      }

      formRefSave.value?.validate().then((err: any) => {
        if (!err) {
          let list = []
          for (let i = 0; i < isDataListss.value.length; i++) {
            var ob = {}
            ob['materialCode'] = isDataListss.value[i].materialCode
            ob['materialName'] = isDataListss.value[i].materialName
            ob['specName'] = isDataListss.value[i].specName
            ob['applyNum'] = isDataListss.value[i].applyNum
            ob['unit'] = isDataListss.value[i].unit
            ob['stockNum'] = isDataListss.value[i].stockNum
            ob['remark'] = isDataListss.value[i].remark
            ob['useCompany'] = dataForm.useCompany
            list.push(ob)
          }
          if (sgTitels.value == '新增申购单') {
            post({
              url: 'dwPurchase/PurchaseApply/add',
              data: {
                ...dataForm,
                updateState: 1,
                purchaseApplyDetail: list,
              }
            }).then((res: any) => {
              if (res.code === 200) {
                for (let item in dataForm) {
                  dataForm[item] = ''
                }
                isDataListss.value = []
                selectedRowKeys1.value = []
                doRefreshs()
                Message.success({
                  content: '保存成功!',
                  duration: 5000,
                })
                isDtasZh.value = false
              } else {
                Message.error(res.message)
              }
            })
          } else {
            post({
              url: 'dwPurchase/PurchaseApply/updateInfo',
              data: {
                ...dataForm,
                purchaseApplyDetail: list,
              },
            }).then((res: any) => {
              if (res.code == 200) {
                for (let item in dataForm) {
                  dataForm[item] = ''
                }
                selectedRowKeys1.value = []
                cxAllInfo()
                Message.success({
                  content: '修改成功!',
                  duration: 5000,
                })
                isDtasZh.value = false
              } else {
                Message.error(res.message)
              }
            })
          }
          formRefSave.value?.resetFields()
        }
      })
    }

    const handleBeforeOks = () => {
      getFirmGroup2()
      post({
        url: 'dwPurchase/PurchaseApply/getAutomaticInfo',
        data: gridOption.value.getSelectedRows(),
      }).then((resss: any) => {
        if (resss.code == 200) {
          dataForm.applyPerson = resss.data.applyPerson
          dataForm.applyCode = resss.data.maxApplyCode
          // if (gridOption.value.getSelectedRows().length > 0) {
          //   dataForm.useCompany = resss.data.hashMap[0].useCompany
          //   dataForm.useCompanys = resss.data.hashMap[0].useCompanys
          //   dataForm.useDepartment = resss.data.hashMap[0].useDepartment
          //   dataForm.useDepartmentId = resss.data.hashMap[0].useDepartmentId
          // }
          getBmGroup1(dataForm.useCompany)
          sgTitels.value = '新增申购单'
          isDtasZh.value = true
        }
      })
    }

    const isDataListss: any = ref([])
    let isTypeIds = 0
    const tjWl = () => {
      // isDataListss.value.unshift({
      //   materialName: '',
      //   specName: '',
      //   unit: '',
      //   needNum: 0,
      //   applyNum: 0,
      //   stockNum: 0,
      //   remark: '',
      //   isTypeIds: isTypeIds++,
      // })
      visibleWl.value = true
    }

    const scWls = () => {
      if (selectedRowKeys1.value.length == 0) {
        Message.error('请选择要删除的数据')
        return
      }

      if (sgTitels.value == '修改申购单') {
        if (selectedRowKeys1.value.length > 1) {
          // isDataLists.value.forEach((item:any,index:any)=>{
          //     selectedRowKeys1.value.forEach((items:any,indexs:any)=>{
          //         if(item.materialName == items){
          //             isDataLists.value.splice(index,1)
          //             selectedRowKeys1.value.splice(indexs,1)
          //         }
          //     })
          // })
          selectedRowKeys1.value.forEach((item: any, index: any) => {
            isDataListss.value.forEach((items: any, indexs: any) => {
              if (item == items.isTypeIds) {
                // selectedRowKeys1.value.splice(index,1)
                isDataListss.value.splice(indexs, 1)
                return
              }
            })
          })
          if (selectedRowKeys1.value.length > isDataListss.value.length) {
            selectedRowKeys1.value = []
          }
        } else {
          isDataListss.value.some((item: any, index: any) => {
            if (selectedRowKeys1.value[0] == item.isTypeIds) {
              isDataListss.value.splice(index, 1)
              selectedRowKeys1.value = []
            }
          })
        }
      } else if (sgTitels.value == '新增申购单') {
        if (selectedRowKeys1.value.length > 1) {
          // isDataLists.value.forEach((item:any,index:any)=>{
          //     selectedRowKeys1.value.forEach((items:any,indexs:any)=>{
          //         if(item.materialName == items){
          //             isDataLists.value.splice(index,1)
          //             selectedRowKeys1.value.splice(indexs,1)
          //         }
          //     })
          // })
          selectedRowKeys1.value.forEach((item: any, index: any) => {
            isDataListss.value.forEach((items: any, indexs: any) => {
              if (item == items.isTypeIds) {
                // selectedRowKeys1.value.splice(index,1)
                isDataListss.value.splice(indexs, 1)
              }
            })
          })
          if (selectedRowKeys1.value.length > isDataListss.value.length) {
            selectedRowKeys1.value = []
          }
        } else {
          isDataListss.value.some((item: any, index: any) => {
            if (selectedRowKeys1.value == item.isTypeIds) {
              isDataListss.value.splice(index, 1)
              selectedRowKeys1.value = []
            }
          })
        }
      }
    }

    //下拉框得到焦点
    const focusSelsm = () => {
      selCxAllsm({materialName: '', auditState: 1})
    }
    //下拉数据
    const optionssm: any = ref()
    const loadingsm = ref(false)
    const handleSearchsm = (value: any) => {
      if (value) {
        const ob = {materialName: value, auditState: 1}
        loadings.value = true
        window.setTimeout(() => {
          selCxAllsm(ob)
          loadingsm.value = false
        }, 200)
      } else {
        optionssm.value = []
      }
    }

    //下拉框查询
    function selCxAllsm(val: any) {
      post({
        url: 'dwPurchase/MaterialInfo/getFieldValue',
        data: val,
      }).then(({data, code, message}: any) => {
        if (code === 200) {
          optionssm.value = data
        } else {
          Message.error({
            content: message,
            duration: 5000,
          })
        }
      })
    }

    const handles = (record: any) => {
      record.specName = ''
      record.unit = ''
      record.materialCode = ''
      post({
        url: 'dwPurchase/MaterialInfo/getList',
        data: {
          materialName: record.materialName,
        },
      }).then((res: any) => {
        if (res.code == 200) {
          // ckNum2()
          record.specName = res.data[0].specName
          record.unit = res.data[0].unit
          record.materialCode = res.data[0].materialCode
        }
        ckNum()
        ckNum2()
        ckNum3()
        ckNum4()
      })
    }
    const sgTitels = ref()

    const isWlCodeList: any = ref([])
    const hqWlCode = () => {
      wlCode({materialCode: '', auditState: 1})
    }
    const hqWlCodes = (val: any) => {
      wlCode({materialCode: val, auditState: 1})
    }

    function wlCode(val: any) {
      post({
        url: 'dwPurchase/MaterialInfo/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          // (data as string[]).splice(0, 0, "全部");
          isWlCodeList.value = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    const hqWlCodezs = (record: any) => {
      record.specName = ''
      record.unit = ''
      record.materialName = ''
      post({
        url: 'dwPurchase/MaterialInfo/getList',
        data: {
          materialCode: record.materialCode,
        },
      }).then((res: any) => {
        if (res.code == 200) {
          // ckNum2()
          record.specName = res.data[0].specName
          record.unit = res.data[0].unit
          record.materialName = res.data[0].materialName
        }
        ckNum()
        ckNum2()
        ckNum3()
        ckNum4()
      })
    }
    const localeText1: any = ref(localeText)
    const huiche = () => {
      doRefreshs()
    }
    const pagingList1: any = ref(pagingList)

    // 获取公司列表
    const getFirmGroup = () => {
      get({
        url: '/admin/acl/user/getMemberIdByJwtToken',
      }).then((res) => {
        post({
          url: 'admin/acl/user/findUserToken',
          data: {
            name: res,
          },
        }).then((res: any) => {
          if (res.code === 200) {
            dataForm.applyCompanys = res.data.data.firmName
            dataForm.applyCompany = res.data.data.firmId
            dataForm.applyDepartment = res.data.data.department
            dataForm.applyDepartmentId = res.data.data.departmentId
            getBmGroup(dataForm.applyCompany)
            post({
              url: 'org/baCompany/getTreeCompanyByUser',
              data: {},
            }).then(({code, data}) => {
              if (code === 200) {
                pageData.firmGroupList = data
                pageData.firmGroupList1 = data
                pageData.nameListq1 = data
                getBmGroup(dataForm.applyCompany)
              }
            })
          } else {
            Message.error({
              content: res.message,
              duration: 5000,
            })
          }
        })
      })
    }
    //创建申购单 公司根据账号回显
    const getFirmGroup2 = () => {
      get({
        url: '/admin/acl/user/getMemberIdByJwtToken',
      }).then((res) => {
        post({
          url: 'admin/acl/user/findUserToken',
          data: {
            name: res,
          },
        }).then((res: any) => {
          if (res.code === 200) {
            dataForm.applyCompanys = res.data.data.firmName
            dataForm.applyCompany = res.data.data.firmId
            dataForm.applyDepartment = res.data.data.department
            dataForm.applyDepartmentId = res.data.data.departmentId
            dataForm.useCompanys = res.data.data.firmName
            dataForm.useCompany = res.data.data.firmId
            dataForm.useDepartment = res.data.data.department
            dataForm.useDepartmentId = res.data.data.departmentId
            getBmGroup1(dataForm.useCompany)
            getBmGroup(dataForm.applyCompany)
            post({
              url: 'org/baCompany/getTreeCompanyByUser',
              data: {},
            }).then(({code, data}) => {
              if (code === 200) {
                pageData.firmGroupList = data
                pageData.firmGroupList1 = data
                pageData.nameListq1 = data
                getBmGroup(dataForm.applyCompany)
              }
            })
          } else {
            Message.error({
              content: res.message,
              duration: 5000,
            })
          }
        })
      })
    }
    let casOb = ref()
    const casOb1 = ref()
    //公司改变
    const cascaderChange = (event: any, val: any) => {
      //拿到选中的这个节点数组
      setTimeout(function () {
        if (casOb.value.selectViewValue.length != 0) {
          pageData.title = slicing(casOb.value.selectViewValue[0]['label'])
          dataForm.applyCompanys = slicing(casOb.value.selectViewValue[0]['label'])
        }
      }, 100)
      getBmGroup(val)
      dataForm.applyDepartmentId = ''
      pageData.bmList = []
    }
    //部门改变
    const cascaderChange1 = (val: any) => {
      //拿到选中的这个节点数组
      setTimeout(function () {
        if (casOb1.value.selectViewValue.length != 0) {
          pageData.title1 = slicing(casOb1.value.selectViewValue[0]['label'])
          dataForm.applyDepartment = slicing(casOb1.value.selectViewValue[0]['label'])
          dataForm.applyDepartmentId = val
        }
      }, 100)
    }
    const casOb2 = ref()
    const casOb3 = ref()
    //公司改变
    const cascaderChange2 = (event: any, val: any) => {
      //拿到选中的这个节点数组
      setTimeout(function () {
        if (casOb2.value.selectViewValue.length != 0) {
          pageData.title2 = slicing(casOb2.value.selectViewValue[0]['label'])
          dataForm.useCompanys = slicing(casOb2.value.selectViewValue[0]['label'])
        }
      }, 100)
      getBmGroup1(val)
      console.log(dataForm.useDepartmentId)
      ckNum()
      dataForm.useDepartmentId = ''
      pageData.bmList1 = []
    }
    //公司改变
    const cascaderChanges2 = (event: any, val: any) => {
      //拿到选中的这个节点数组
      setTimeout(function () {
        if (casOb2.value.selectViewValue.length != 0) {
          pageData.title2 = slicing(casOb2.value.selectViewValue[0]['label'])
          dataForm.useCompanys = slicing(casOb2.value.selectViewValue[0]['label'])
        }
      }, 100)
      getBmGroup1(val)
      ckNum2()
      dataForm.useDepartmentId = ''
      pageData.bmList1 = []
    }
    //部门改变
    const cascaderChange3 = (val: any) => {
      //拿到选中的这个节点数组
      setTimeout(function () {
        if (casOb3.value.selectViewValue.length != 0) {
          pageData.title3 = slicing(casOb3.value.selectViewValue[0]['label'])
          dataForm.useDepartment = slicing(casOb3.value.selectViewValue[0]['label'])
          dataForm.useDepartmentId = val
        }
      }, 100)
    }
    const loadingbm = ref<boolean>(false)
    // 获取部门列表
    loadingbm.value = true
    const getBmGroup1 = (val: any) => {
      post({
        url: 'org/baCompany/getDepartmentTree?companyId=' + val,
      })
          .then((result) => {
            if (result.code === 200) {
              pageData.bmList1 = result.data
            }
            loadingbm.value = false
          })
          .catch(() => {
            loadingbm.value = false
          })
    }
    // 获取部门列表
    const getBmGroup = (val: any) => {
      post({
        url: 'org/baCompany/getDepartmentTree?companyId=' + val,
      }).then((result) => {
        if (result.code === 200) {
          pageData.bmList = result.data
        }
      })
    }

    //搜索框 公司部门改变
    const casOb5 = ref()
    const casOb6 = ref()
    const cascaderChange5 = (event: any, val: any) => {
      setTimeout(function () {
        if (casOb5.value.selectViewValue.length != 0) {
          pageData.title5 = slicing(casOb5.value.selectViewValue[0]['label'])
          isDatas.iss = slicing(casOb5.value.selectViewValue[0]['label'])
        }
      }, 100)
      getBmGroup6(val)
      doRefreshs()
      pageData.nameListq = []
      isDatas.is1 = ''
    }
    const cascaderChange6 = (val: any) => {
      setTimeout(function () {
        if (casOb6.value.selectViewValue.length != 0) {
          pageData.title6 = slicing(casOb6.value.selectViewValue[0]['label'])
          isDatas.is1s = slicing(casOb6.value.selectViewValue[0]['label'])
        }
      }, 100)
      doRefreshs()
    }
    //搜索框  获取部门列表
    const getBmGroup6 = (val: any) => {
      post({
        url: 'org/baCompany/getDepartmentTree?companyId=' + val,
      }).then((result) => {
        if (result.code === 200) {
          pageData.nameListq = result.data
        }
      })
    }

    const huiche3 = () => {
      cxAllYtj()
    }
    const huiche2 = () => {
      selectInfo()
    }
    const typeChange = () => {
      doRefreshs()
    }
    //创建申购单 库存数量
    const ckNum2 = () => {
      post({
        url: '/wms/ironwareStockSummary/getStockNumProcurement',
        data: isDataListss.value.map((item: any) => {
          return {
            materialCode: item.materialCode,
            companyId: dataForm.useCompany,
            materialName: item.materialName,
          }
        }),
      }).then((res: any) => {
        const {data} = res
        isDataListss.value.map((item: any, index: any) => {
          if (item.materialCode == data[index].materialCode) {
            item.stockNum = data[index].stockNum
          }
        })
      })
    }
    //需求单创建申购单 库存数量
    const ckNum = () => {
      post({
        url: '/wms/ironwareStockSummary/getStockNumProcurement',
        data: gridOption.value.getSelectedRows().map((item: any) => {
          return {
            materialCode: item.materialCode,
            companyId: item.useCompany,
            materialName: item.materialName,
          }
        }),
      }).then((res: any) => {
        const {data} = res
        pageData.tqDataList.forEach((item: any, index: any) => {
          data.forEach((item1: any) => {
            if (item.materialCode == item1.materialCode) {
              item.stockNum = item1.stockNum
              pageData1.showAdd = true
              if (Number(item.stockNum) >= Number(item.applyNum)) {
                Message.warning(`物料名为 ${item.materialName} 的单据有库存!`)
                pageData1.showAdd = true
              }
            }
          })
        })
      })
    }
    //详情中的 库存数量
    const ckNum3 = () => {
      post({
        url: '/wms/ironwareStockSummary/getStockNumProcurement',
        data: pageData.isDetailsList.map((item: any) => {
          return {
            materialCode: item.materialCode,
            companyId: gridOptions.value.getSelectedRows()[0].useCompany,
            materialName: item.materialName,
          }
        }),
      }).then((res: any) => {
        const {data} = res
        pageData.isDetailsList.map((item: any, index: any) => {
          if (item.materialCode == data[index].materialCode) {
            item.stockNum = data[index].stockNum
          }
        })
      })
    }
    //修改中 库存数量
    const ckNum4 = () => {
      post({
        url: '/wms/ironwareStockSummary/getStockNumProcurement',
        data: pageData.tqDataList.map((item: any) => {
          return {
            materialCode: item.materialCode,
            companyId: gridOptions.value.getSelectedRows()[0].useCompany,
            materialName: item.materialName,
          }
        }),
      }).then((res: any) => {
        const {data} = res
        pageData.tqDataList.map((item: any, index: any) => {
          if (item.materialCode == data[index].materialCode) {
            item.stockNum = data[index].stockNum
          }
        })
      })
    }

    const overrule = () => {
      visible6.value = true
    }

    const visible6 = ref(false)
    const okk = () => {
      post({
        url: '/dwPurchase/purchaseNeedDetail/audit',
        data: {
          list1: gridOption.value.getSelectedRows(),
          list2: gridOptionsz111.value.getSelectedRows(),
          rejectState: 1,
          rejectCause: dataForm.rejectCause,
        },
      }).then((res: any) => {
        if (res.code === 200) {
          doRefresh()
          Message.success('订单已驳回')
          selectedRowKeys.value = []
          visible6.value = false
        } else {
          Message.error(res.message)
        }
      })
    }

    //添加物料 弹窗
    const selectedRowKeys3: any = ref([])
    let dataList: any = ref([])
    const materialCode: any = ref('')
    const materialName: any = ref('')
    const bigClassName: any = ref('')
    const subClassName: any = ref('')
    const specName: any = ref('')
    const visibleWl = ref(false)
    const listPage: any = reactive({
      total: 0,
      size: 10,
      page: 1,
    })
    const PageSize3 = (val: any) => {
      listPage.page = val
      listQuery()
    }

    const change3 = (val: any) => {
      listPage.size = val
      listQuery()
    }

    const tableColumns5 = useTableColumn([
      {
        title: '物料大类',
        key: 'bigClassName',
        dataIndex: 'bigClassName',
        width: 300,
      },
      {
        title: '物料小类',
        key: 'subClassName',
        dataIndex: 'subClassName',
        width: 300,
      },
      {
        title: '物料编号',
        key: 'materialCode',
        dataIndex: 'materialCode',
        width: 300,
      },
      {
        title: '物料名称',
        key: 'materialName',
        dataIndex: 'materialName',
        width: 300,
      },
      {
        title: '规格',
        key: 'specName',
        dataIndex: 'specName',
        width: 300,
      },
      {
        title: '单位',
        key: 'unit',
        dataIndex: 'unit',
        width: 300,
      },
      {
        title: '图片',
        key: 'picture',
        dataIndex: 'picture',
        slotName: 'picture',
        width: 150,
      }
    ])

    const Query = () => {
      listPage.page = 1
      listQuery()
    }
    const listQuery = () => {
      pageData.pageLoading = true
      post({
        url: 'dwPurchase/MaterialInfo/getPage',
        data: {
          page: listPage.page,
          size: listPage.size,
          deleteState: 0,
          materialName: materialName.value,
          materialCode: materialCode.value,
          bigClassName: bigClassName.value,
          subClassName: subClassName.value,
          specName: specName.value,
          auditState: 1,
        },
      })
          .then(({data, code}: any) => {
            if (code === 200) {
              listPage.total = data.total
              dataList.value = data.list
              dataList.value.forEach((item: any) => {
                item['isTypeIds'] = isTypeIds++
              })
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
    }
    const handleOk = () => {
      if (selectedRowKeys3.value.length === 0) {
        Message.error('请勾选数据!')
        return false
      }

      let listArray: any = []
      for (let i = 0; i < dataList.value.length; i++) {
        if (selectedRowKeys3.value.includes(dataList.value[i].isTypeIds)) {
          listArray.push(dataList.value[i])
        }
      }
      if (isDataListss.value.length != 0) {
        let wlAarray: any = []
        for (let i = 0; i < listArray.length; i++) {
          wlAarray.push(listArray[i].materialCode)
        }
        for (let i = 0; i < isDataListss.value.length; i++) {
          if (wlAarray.includes(isDataListss.value[i].materialCode)) {
            Message.error(`不能重复添加物料名为 ${isDataListss.value[i].materialName} 的单据!`)
            return false
          }
        }
      }
      listArray.forEach((e: any) => {
        e['materialCode'] = e['materialCode']
        e['materialName'] = e['materialName']
        e['specName'] = e['specName']
        e['unit'] = e['unit']
        e['id'] = null
        e['isTypeIds'] = isTypeIds++
      })
      isDataListss.value.push(...listArray)
      ckNum2()
      materialCode.value = ''
      materialName.value = ''
      bigClassName.value = ''
      subClassName.value = ''
      specName.value = ''
      dataList.value = []
      selectedRowKeys3.value = []
      listPage.total = 0
      visibleWl.value = false
      return true
    }
    const handleCancel = () => {
      materialCode.value = ''
      materialName.value = ''
      bigClassName.value = ''
      subClassName.value = ''
      specName.value = ''
      dataList.value = []
      selectedRowKeys3.value = []
      listPage.total = 0
      visibleWl.value = false
    }

    const permissionStore = usePermission()
    if (permissionStore.hasPermisson('cjsgd.sgdxg1')) {
      pageData.isEdit = true
    }
    if (permissionStore.hasPermisson('cjsgd.sgdxq1')) {
      pageData.isDetail = true
    }
    //下拉框   物料大类  
    const WLfocusSel = () => {
      WLselCxAll({bigClassName: '', auditState: 1})
    }
    const WLoptions = ref<any>(pageData.bigName)
    const WLloading = ref(false)
    const WLhandleSearch = (value: any) => {
      if (value) {
        const ob = {bigClassName: value, auditState: 1}
        WLloading.value = true
        window.setTimeout(() => {
          selCxAll(ob)
          WLoptions.value = pageData.bigName
          WLloading.value = false
        }, 200)
      } else {
        WLoptions.value = []
      }
    }

    function WLselCxAll(val: any) {
      post({
        url: 'dwPurchase/MaterialInfo/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          let list = []
          for (let i = 0; i < data.length; i++) {
            var ob = data[i].bigClassName
            list.push(ob)
          }
          const arr = list
          const setData = Array.from(new Set(arr));
          pageData.bigName = setData
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    const bigChange = () => {
      subClassName.value = ''
      pageData.samllName = []
    }
    //下拉框   物料小类  
    const WLfocusSel1 = () => {
      WLselCxAll1({subClassName: '', auditState: 1})
    }
    const WLoptions1 = ref<any>(pageData.samllName)
    const WLloading1 = ref(false)
    const WLhandleSearch1 = (value: any) => {
      if (value) {
        const ob = {subClassName: value, auditState: 1}
        WLloading.value = true
        window.setTimeout(() => {
          WLselCxAll1(ob)
          WLoptions.value = pageData.samllName
          WLloading.value = false
        }, 200)
      } else {
        WLoptions.value = []
      }
    }

    function WLselCxAll1(val: any) {
      if (bigClassName.value === '') {
        Message.warning('请先选择物料大类！')
        pageData.samllName = []
      }
      post({
        url: 'dwPurchase/MaterialInfo/getList',
        data: {
          bigClassName: bigClassName.value
        }
      }).then(({data, code}: any) => {
        if (code === 200) {
          let list = []
          for (let i = 0; i < data.length; i++) {
            var ob = data[i].subClassName
            list.push(ob)
          }
          const arr = list
          const setData = Array.from(new Set(arr));
          pageData.samllName = setData
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    // 下拉框  物料编码 
    const WLfocusSel2 = () => {
      WLselCxAll2({materialCode: '', auditState: 1})
    }
    const WLoptions2 = ref<any>(pageData.codeList)
    const WLloading2 = ref(false)
    const WLhandleSearch2 = (value: any) => {
      if (value) {
        const ob = {materialCode: value, auditState: 1}
        WLloading2.value = true;
        WLselCxAll2(ob);
        WLoptions2.value = pageData.codeList;
        WLloading2.value = false;
      } else {
        WLoptions2.value = []
      }
    }

    function WLselCxAll2(val: any) {
      post({
        url: 'dwPurchase/MaterialInfo/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          pageData.codeList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    const WLhandleCode = (e: any) => {
      materialCode.value = e.split('——')[0]
    }

    // 下拉框  物料名称
    const WLfocusSel3 = () => {
      WLselCxAll3({materialName: '', auditState: 1})
    }
    const WLoptions3 = ref<any>(pageData.wlNameList)
    const WLloading3 = ref(false)
    const WLhandleSearch3 = (value: any) => {
      if (value) {
        const ob = {materialName: value, auditState: 1}
        WLloading3.value = true;
        WLselCxAll3(ob);
        WLoptions3.value = pageData.wlNameList;
        WLloading3.value = false;
      } else {
        WLoptions3.value = []
      }
    }

    function WLselCxAll3(val: any) {
      post({
        url: 'dwPurchase/MaterialInfo/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          pageData.wlNameList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    const WLhandleName = (e: any) => {
      materialName.value = e.split('——')[1]
    }

    // 下拉框  规格
    const WLfocusSel4 = () => {
      WLselCxAll4({specName: '', auditState: 1})
    }
    const WLoptions4 = ref<any>(pageData.specList)
    const WLloading4 = ref(false)
    const WLhandleSearch4 = (value: any) => {
      if (value) {
        const ob = {specName: value, auditState: 1}
        WLloading4.value = true;
        WLselCxAll4(ob);
        WLoptions4.value = pageData.specList;
        WLloading4.value = false;
      } else {
        WLoptions4.value = []
      }
    }

    function WLselCxAll4(val: any) {
      post({
        url: 'dwPurchase/MaterialInfo/getFieldValue',
        data: val,
      }).then(({data, code}: any) => {
        if (code === 200) {
          pageData.specList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    return {
      bigChange,
      WLhandleCode,
      WLhandleName,
      specName,
      WLoptions,
      WLoptions1,
      WLoptions2,
      WLoptions3,
      WLoptions4,
      WLloading,
      WLloading1,
      WLloading2,
      WLloading3,
      WLloading4,
      WLfocusSel,
      WLfocusSel1,
      WLfocusSel2,
      WLfocusSel3,
      WLfocusSel4,
      WLhandleSearch,
      WLhandleSearch1,
      WLhandleSearch2,
      WLhandleSearch3,
      WLhandleSearch4,
      WLselCxAll,
      WLselCxAll1,
      WLselCxAll2,
      WLselCxAll3,
      WLselCxAll4,
      listPage,
      Query,
      listQuery,
      dataList,
      selectedRowKeys3,
      tableColumns5,
      change3,
      PageSize3,
      handleOk,
      handleCancel,
      visibleWl,
      materialCode,
      materialName,
      bigClassName,
      subClassName,
      permissionStore,
      selectHandler,
      okk,
      visible6,
      ckNum4,
      ckNum3,
      tableColumns3,
      cascaderChanges2,
      ckNum,
      ckNum2,
      getFirmGroup2,
      typeChange,
      casOb,
      casOb1,
      casOb2,
      casOb3,
      casOb5,
      casOb6,
      pagingList1,
      getBmGroup1,
      getBmGroup6,
      cascaderChange6,
      cascaderChange5,
      cascaderChange3,
      cascaderChange2,
      cascaderChange,
      cascaderChange1,
      getFirmGroup,
      ygselectlist,
      ygselect,
      tabValue,
      loadingbm,
      tbsData,
      huiche,
      huiche2,
      huiche3,
      localeText1,
      hqWlCodezs,
      hqWlCodes,
      isWlCodeList,
      hqWlCode,
      sgTitels,
      handles,
      focusSelsm,
      handleSearchsm,
      optionssm,
      loadingsm,
      isDataListss,
      scWls,
      tjWl,
      sideOkss,
      cancelDelets,
      isDtasZh,
      handleBeforeOks,
      tcsz111,
      defaultColDefsz111,
      gridReadysz111,
      gridOptionsz111,
      tcsz,
      defaultColDefsz,
      gridReadysz,
      gridOptionsz,
      tcs,
      defaultColDefs,
      gridReadys,
      gridOptions,
      tc,
      defaultColDef,
      gridReady,
      gridOption,
      PageSize,
      change1,
      // changeGs,
      // foucusUseFrim,
      handleSearch2,
      options2,
      loading2,
      cancelDelet,
      xuQiuGg,
      xuQiuGgs,
      xuQiuWl,
      xuQiuWls,
      xuQiuCk,
      xuQiuCks,
      xuQiuLeix,
      xuQiuLeixs,
      xuQiurs,
      xuQiur,
      xuQius,
      isDatas,
      xuQiu,
      paginations11,
      xqOptions,
      zjArrays,
      zjArrays1,
      casaders,
      handleBeforeOk,
      tqxqd,
      visible,
      tableColumns,
      selectSh,
      handleSearchqs,
      focusSelqs,
      loadingqs,
      loadingq,
      focusSelq,
      handleSearchq,
      scWl,
      cancelsDel,
      focusSelz,
      handleSearchz,
      selectedRowKeys1,
      isDataLists,
      sideOks,
      handleSearchs,
      focusSels,
      isDataList,
      tableColumns1,
      formRef,
      formRefSave,
      dataForm,
      selectedRowKeys,
      pagination,
      pagination2,
      table,
      rowKey,
      pageData,
      onClose,
      selectInfo,
      inputBlur,
      isChiese,
      editHandler,
      options,
      loading,
      handleSearch,
      focusSel,
      cxAllInfo,
      changetabs,
      headerShow,
      pageData1,
      pagination1,
      visible1,
      visible1s,
      cxDetails,
      tableColumns2,
      submit,
      focusSel1,
      options1,
      loading1,
      handleSearch1,
      cxAllYtj,
      onSelect(dateString: any, date: any) {
        pageData.dropDownDataqszs = {
          startDate: dateString[0],
          endDate: dateString[1],
        }
      },
      onClear() {
        pageData.dropDownDataqszs = {}
      },
      addXqiu() {
        formRef.value?.validate().then((err) => {
          if (!err) {
            if (isDataLists.value.length == 0) {
              Message.error('请提取需求单')
              return
            } else {
              dataForm.id = null
              pageData.xqDataList.forEach(function (o: any) {
                o['id'] = undefined
              })
              post({
                url: 'dwPurchase/PurchaseApply/insert',
                data: {
                  ...dataForm,
                  purchaseApplyDetail: pageData.xqDataList,
                },
              }).then((res: any) => {
                if (res.code === 200) {
                  formRef.value?.resetFields()
                  isDataLists.value = []
                  Message.success({
                    content: '新增成功',
                    duration: 5000,
                  })
                } else {
                  Message.error({
                    content: res.message,
                    duration: 5000,
                  })
                }
              })
            }
          }
        })
      },
      delQk() {
        formRef.value?.resetFields()
        isDataLists.value = []
      },
    }
  },
  components: {Toolbar, },
}
</script>
<style scoped lang="less">
.xqdxx {
  display: flex;
}

:deep(.arco-table-td-content) {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>